Issue 52944
Summary Wc++20-designator gives warnings from macros defined in system headers
Labels clang:frontend
Assignees
Reporter carlosgalvezp
    Hi,

I find that `-Wc++20-designator` (which I get via `-pedantic`) is giving warnings from system headers, which is strange and inconsistent with GCC. The point of system headers is to suppress warnings from them in a clean way - system headers are not to be patched by users, so warnings cannot be acted upon. Currently we need to suppress warnings to the whole .cpp file that includes such a header due to warnings from system macros not being ignored, which may lower the quality of the whole file.

I have asked in [cfe-dev](https://reviews.llvm.org/D116378) without answer, and posted in [StackOverflow](https://stackoverflow.com/questions/70488470/how-to-ignore-compiler-warnings-for-macros-defined-in-third-party-headers) where I got feedback that this is most likely a bug, so I'm raising it here.

Example code that doesn't give warnings in GCC (9.4.0), but does in Clang (14.0.0):

```cpp
// include/third_party2.h
#pragma once

struct Foo
{
    int x;
    int y;
};

#define FOO Foo{.x = 123, .y = 321}
```

```cpp
// main2.cpp
#include <third_party2.h>

int main() 
{
    Foo f = FOO;
    return f.x;
}
```

```cpp
$ g++ -isystem include -pedantic main2.cpp
$
```
```cpp
$ clang++ -isystem include -pedantic main2.cpp 
main2.cpp:5:13: warning: designated initializers are a C++20 extension [-Wc++20-designator]
    Foo f = FOO;
            ^
include/third_party2.h:9:17: note: expanded from macro 'FOO'
#define FOO Foo{.x = 123, .y = 321}
                ^
1 warning generated.
```

Does this make sense? I'm happy to fix it myself but I need some guidance.

Thanks!
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to