clang-cl behaves different on attributes than MSVC
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When using the attribute `[[nodiscard]]` after `__declspec(dllexport)`, the compiler complains:
```
(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](https://godbolt.org/z/4cYYW938r)
- MSVC v19.20 [Godbolt](https://godbolt.org/z/ra8h57Eqa)
Complete example:
```
enum bar {
bar1 = 0
};
__declspec(dllexport) [[nodiscard]] bar foo() {
return bar::bar1;
}
int main() {
foo();
return 0;
}
```
Contributor guide
Research direction
Start by compiling the complete example with clang-cl using both attribute orders, then compare the diagnostics with MSVC and the linked Godbolt examples. Trace clang-cl's handling of __declspec(dllexport) and [[nodiscard]] placement; done means the accepted behavior matches MSVC for either order without misapplying nodiscard to a type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100