llvm-project/clang/test/Parser/namespace-attributes.cpp
Aleksandr Platonov 8bd00557e3 [clang][parser] Allow GNU attributes before namespace identifier
GCC supports:
- `namespace <gnu attributes> identifier`
- `namespace identifier <gnu attributes>`

But clang supports only `namespace identifier <gnu attributes>` and diagnostics for `namespace <gnu attributes> identifier` case looks unclear:
Code:
```
namespace __attribute__((visibility("hidden"))) A
{
}
```
Diags:
```
test.cpp:1:49: error: expected identifier or '{'
namespace __attribute__((visibility("hidden"))) A
                                                ^
test.cpp:1:49: error: C++ requires a type specifier for all declarations
test.cpp:3:2: error: expected ';' after top level declarator
}
```

This patch adds support for `namespace <gnu attributes> identifier` and also forbids gnu attributes for nested namespaces (this already done for C++ attributes).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D121245
2022-03-15 22:30:22 +03:00

42 lines
597 B
C++

// RUN: %clang_cc1 -std=c++17 -verify %s
namespace __attribute__(()) A
{
}
namespace A __attribute__(())
{
}
namespace __attribute__(()) [[]] A
{
}
namespace [[]] __attribute__(()) A
{
}
namespace A __attribute__(()) [[]]
{
}
namespace A [[]] __attribute__(())
{
}
namespace [[]] A __attribute__(())
{
}
namespace __attribute__(()) A [[]]
{
}
namespace A::B __attribute__(()) // expected-error{{attributes cannot be specified on a nested namespace definition}}
{
}
namespace __attribute__(()) A::B // expected-error{{attributes cannot be specified on a nested namespace definition}}
{
}