Skip to content

Unable to build shared libraries with Clang for Windows #291

@HC-pel

Description

@HC-pel

Clang appears to be pickier than MSVC about where attribute lists are allowed to appear, leading to errors such as the following:

[...]\include\graphqlservice/GraphQLParse.h(43,21): error: 'nodiscard' attribute cannot be applied to types
GRAPHQLPEG_EXPORT [[nodiscard]] ast parseSchemaFile(
                    ^
[...]\include/graphqlservice/GraphQLService.h(170,24): error: an attribute list cannot appear here
        GRAPHQLSERVICE_EXPORT [[nodiscard]] bool await_ready() const;
                              ^~~~~~~~~~~~~

Moving the [[nodiscard]] before the export macro will fix both types of errors. I'm not sure who exactly is to blame for this, as __declspec is of course a Microsoft extension and Clang tries to maintain compatibility with MSVC, but it would be nice to be able to build with both compilers.

I've written a minimal example here: https://godbolt.org/z/5WfvP4Gea

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions