Skip to content

clang-cl behaves different on attributes than MSVC #167835

@Jimbopython

Description

@Jimbopython

When using the attribute [[nodiscard]] after __declspec(dllexport), the compiler complains:

<source>(5,25): error: 'nodiscard' attribute cannot be applied to types

When swapping the [[nodiscard]] and __declspec(dllexport), the compilation succeeds.

This behavior is different from MSVC, as MSVC does not care about the order of the arguments.

Tested with

  • clang-cl 20.1.8 on Ubuntu
  • clang-cl 18.1.0 Godbolt
  • MSVC v19.20 Godbolt

Complete example:

enum bar {
    bar1 = 0
};

__declspec(dllexport) [[nodiscard]] bar foo() {
    return bar::bar1;
}


int main() {
    foo();
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partydiverges-from:msvcDoes the clang frontend diverge from msvc on this issueextension:microsoft

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions