[clang] Enable C++11-style attributes in all language modes
This also ignores and deprecates the `-fdouble-square-bracket-attributes` command line flag, which seems to not be used anywhere. At least a code search exclusively found mentions of it in documentation: https://sourcegraph.com/search?q=context:global+-fdouble-square-bracket-attributes+-file:clang/*+-file:test/Sema/*+-file:test/Parser/*+-file:test/AST/*+-file:test/Preprocessor/*+-file:test/Misc/*+archived:yes&patternType=standard&sm=0&groupBy=repo
RFC: https://discourse.llvm.org/t/rfc-enable-c-11-c2x-attributes-in-all-standard-modes-as-an-extension-and-remove-fdouble-square-bracket-attributes
This enables `[[]]` attributes in all C and C++ language modes without warning by default. `-Wc++-extensions` does warn. GCC has enabled this extension in all C modes since GCC 10.
Reviewed By: aaron.ballman, MaskRay
Spies: #clang-vendors, beanz, JDevlieghere, Michael137, MaskRay, sstefan1, jplehr, cfe-commits, lldb-commits, dmgreen, jdoerfert, wenlei, wlei
Differential Revision: https://reviews.llvm.org/D151683
2023-07-22 09:33:55 -07:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -verify
|
2008-02-21 19:44:16 +00:00
|
|
|
|
2013-07-23 19:30:11 +00:00
|
|
|
void __attribute__((annotate("foo"))) foo(float *a) {
|
2008-02-21 19:44:16 +00:00
|
|
|
__attribute__((annotate("bar"))) int x;
|
2018-01-03 22:22:48 +00:00
|
|
|
[[clang::annotate("bar")]] int x2;
|
2024-10-10 12:21:34 -04:00
|
|
|
[[clang::annotate("bar")]] x2 += 1;
|
2021-07-10 15:52:54 +02:00
|
|
|
__attribute__((annotate(1))) int y; // expected-error {{expected string literal as argument of 'annotate' attribute}}
|
|
|
|
[[clang::annotate(1)]] int y2; // expected-error {{expected string literal as argument of 'annotate' attribute}}
|
2020-10-26 09:58:20 +01:00
|
|
|
__attribute__((annotate("bar", 1))) int z;
|
|
|
|
[[clang::annotate("bar", 1)]] int z2;
|
2024-10-10 12:21:34 -04:00
|
|
|
[[clang::annotate("bar", 1)]] z2 += 1;
|
2018-01-03 22:22:48 +00:00
|
|
|
|
2012-04-28 17:39:16 +00:00
|
|
|
int u = __builtin_annotation(z, (char*) 0); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
|
|
|
|
int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
|
2011-09-09 22:41:49 +00:00
|
|
|
int w = __builtin_annotation(z, "foo");
|
2012-04-28 17:39:16 +00:00
|
|
|
float b = __builtin_annotation(*a, "foo"); // expected-error {{first argument to __builtin_annotation must be an integer}}
|
2022-02-08 13:27:52 -05:00
|
|
|
|
|
|
|
__attribute__((annotate())) int c; // expected-error {{'annotate' attribute takes at least 1 argument}}
|
|
|
|
[[clang::annotate()]] int c2; // expected-error {{'annotate' attribute takes at least 1 argument}}
|
2024-10-10 12:21:34 -04:00
|
|
|
[[clang::annotate()]] c2 += 1; // expected-error {{'annotate' attribute takes at least 1 argument}}
|
2008-02-21 19:44:16 +00:00
|
|
|
}
|