llvm / llvm/llvm-project

[clang] error: attribute 'nothrow' cannot be applied to 'function'

Open
#191,487 5 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

For some reason pragma attribute push for nothrow doesn't work.

```c
#pragma clang attribute push(__attribute__((nothrow)), apply_to=function)

int foo() {
return 42;
}

#pragma clang attribute pop
```

https://godbolt.org/z/s6j8xe5Ej

```
:1:15: error: attribute 'nothrow' cannot be applied to 'function'
1 | #pragma clang attribute push(__attribute__((nothrow)), apply_to=function)
| ^ ~~~~~~~~
:1:45: warning: unused attribute 'nothrow' in '#pragma clang attribute push' region [-Wpragma-clang-attribute]
1 | #pragma clang attribute push(__attribute__((nothrow)), apply_to=function)
| ^
:7:15: note: '#pragma clang attribute push' regions ends here
7 | #pragma clang attribute pop
| ^
1 warning and 1 error generated.
Compiler returned: 1
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the diagnostic with the C snippet in the issue and compare the behavior in the linked Godbolt example. Trace Clang's pragma-attribute handling and attribute applicability checks; done means the pragma accepts nothrow for functions without the reported error or unused-attribute warning, with coverage for the example behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.