[clang:frontend] Nonsensical warning for [[gnu::__gnu_inline__]]
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c++
#include
struct fooerr : std::runtime_error
{
using runtime_error::runtime_error;
[[gnu::__gnu_inline__]]
constexpr inline ~fooerr() override = default;
};
void foo() {
throw fooerr("");
}
```
Clang emits the warning "warning: 'gnu_inline' attribute without 'extern' in C++ treated as externally available, this changed in Clang 10 [-Wgnu-inline-cpp-without-extern]"
but class methods can't be declared extern.
The attribute is needed to make GCC consider the fooerr type 'vtables_uniquely_emitted' and therefore avoid emitting the vtable in every TU that defines the class.
Currently, Clang doesn't implement the same behaviour. The only workaround I am aware of is to declare a dummy virtual method to be considered the 'key-method' for the class, which is never actually used.
```c++
struct fooerr : std::runtime_error
{
using runtime_error::runtime_error;
private:
// Only to avoid emitting the vtable in every TU.
virtual void dummy();
public:
// [[gnu::__gnu_inline__]]
constexpr inline ~fooerr() override = default;
};
```
Constexpr exception implementations conflict with the "key-method" heuristic to decide which TU should emit the vtable for a class. There should be a supported and documented way to solve this issue, possibly without requiring different code for Clang and GCC.
Contributor guide
Research direction
Start by compiling the minimal C++ reproduction and inspect Clang's frontend handling of [[gnu::__gnu_inline__]] and the -Wgnu-inline-cpp-without-extern diagnostic. Compare the warning behavior with GCC's vtable emission behavior; done means Clang provides a supported, documented way to avoid unnecessary vtable emission without a dummy key method or compiler-specific code.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100