]> granicus.if.org Git - clang/commitdiff
Add a new language mode for C2x; enable [[attribute]] support by default in C2x.
authorAaron Ballman <aaron@aaronballman.com>
Tue, 14 May 2019 12:09:55 +0000 (12:09 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 14 May 2019 12:09:55 +0000 (12:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360667 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.def
include/clang/Frontend/LangStandard.h
include/clang/Frontend/LangStandards.def
lib/Frontend/CompilerInvocation.cpp
test/Driver/unknown-std.c
test/Parser/c2x-attributes.c
test/Sema/attr-cx2.c
test/Sema/attr-deprecated-c2x.c
test/Sema/c2x-maybe_unused-errors.c
test/Sema/c2x-maybe_unused.c
test/Sema/c2x-nodiscard.c

index 330f788be12e689683bb93299e3718163265c690..74186a1a6b754cf768d0fb604b38a5a84b6b1393 100644 (file)
@@ -82,6 +82,7 @@
 LANGOPT(C99               , 1, 0, "C99")
 LANGOPT(C11               , 1, 0, "C11")
 LANGOPT(C17               , 1, 0, "C17")
+LANGOPT(C2x               , 1, 0, "C2x")
 LANGOPT(MSVCCompat        , 1, 0, "Microsoft Visual C++ full compatibility mode")
 LANGOPT(MicrosoftExt      , 1, 0, "Microsoft C++ extensions")
 LANGOPT(AsmBlocks         , 1, 0, "Microsoft inline asm blocks")
index 406ca56cc395b2672b3904be86a410b9a8e6b615..244f14c793de03c622c1365038c6949fe3122262 100644 (file)
@@ -22,16 +22,17 @@ enum LangFeatures {
   C99 = (1 << 1),
   C11 = (1 << 2),
   C17 = (1 << 3),
-  CPlusPlus = (1 << 4),
-  CPlusPlus11 = (1 << 5),
-  CPlusPlus14 = (1 << 6),
-  CPlusPlus17 = (1 << 7),
-  CPlusPlus2a = (1 << 8),
-  Digraphs = (1 << 9),
-  GNUMode = (1 << 10),
-  HexFloat = (1 << 11),
-  ImplicitInt = (1 << 12),
-  OpenCL = (1 << 13)
+  C2x = (1 << 4),
+  CPlusPlus = (1 << 5),
+  CPlusPlus11 = (1 << 6),
+  CPlusPlus14 = (1 << 7),
+  CPlusPlus17 = (1 << 8),
+  CPlusPlus2a = (1 << 9),
+  Digraphs = (1 << 10),
+  GNUMode = (1 << 11),
+  HexFloat = (1 << 12),
+  ImplicitInt = (1 << 13),
+  OpenCL = (1 << 14)
 };
 
 }
@@ -73,6 +74,9 @@ public:
   /// isC17 - Language is a superset of C17.
   bool isC17() const { return Flags & frontend::C17; }
 
+  /// isC2x - Language is a superset of C2x.
+  bool isC2x() const { return Flags & frontend::C2x; }
+
   /// isCPlusPlus - Language is a C++ variant.
   bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; }
 
index 2fe6eb88abf47f3151a2c16471d992b91c7f7d3a..44a080d6d12fcf5e9fe25c9b4a14e420c874d313 100644 (file)
@@ -88,6 +88,14 @@ LANGSTANDARD(gnu17, "gnu17",
              LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat)
 LANGSTANDARD_ALIAS(gnu17, "gnu18")
 
+// C2x modes
+LANGSTANDARD(c2x, "c2x",
+             C, "Working Draft for ISO C2x",
+             LineComment | C99 | C11 | C17 | C2x | Digraphs | HexFloat)
+LANGSTANDARD(gnu2x, "gnu2x",
+             C, "Working Draft for ISO C2x with GNU extensions",
+             LineComment | C99 | C11 | C17 | C2x | Digraphs | GNUMode | HexFloat)
+
 // C++ modes
 LANGSTANDARD(cxx98, "c++98",
              CXX, "ISO C++ 1998 with amendments",
index c95c67af6a4c753f33b696bc494b4032e4bcb404..e9137bb73c9cd74a39d81d53f6a63b1c9987922d 100644 (file)
@@ -2134,6 +2134,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
   Opts.C99 = Std.isC99();
   Opts.C11 = Std.isC11();
   Opts.C17 = Std.isC17();
+  Opts.C2x = Std.isC2x();
   Opts.CPlusPlus = Std.isCPlusPlus();
   Opts.CPlusPlus11 = Std.isCPlusPlus11();
   Opts.CPlusPlus14 = Std.isCPlusPlus14();
@@ -2200,6 +2201,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
   Opts.AlignedAllocation = Opts.CPlusPlus17;
 
   Opts.DollarIdents = !Opts.AsmPreprocessor;
+
+  // Enable [[]] attributes in C++11 and C2x by default.
+  Opts.DoubleSquareBracketAttributes = Opts.CPlusPlus11 || Opts.C2x;
 }
 
 /// Attempt to parse a visibility value out of the given argument.
@@ -2605,10 +2609,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
   Opts.Coroutines = Opts.CPlusPlus2a || Args.hasArg(OPT_fcoroutines_ts);
 
-  // Enable [[]] attributes in C++11 by default.
   Opts.DoubleSquareBracketAttributes =
       Args.hasFlag(OPT_fdouble_square_bracket_attributes,
-                   OPT_fno_double_square_bracket_attributes, Opts.CPlusPlus11);
+                   OPT_fno_double_square_bracket_attributes,
+                   Opts.DoubleSquareBracketAttributes);
 
   Opts.CPlusPlusModules = Opts.CPlusPlus2a;
   Opts.ModulesTS = Args.hasArg(OPT_fmodules_ts);
index 86515506511a7e884daf6c8cbf946ddb75172f51..d87a968894b36d0c72790674e3119d6ae9561e51 100644 (file)
@@ -16,6 +16,8 @@
 // CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c17', 'iso9899:2017', 'c18', or 'iso9899:2018' for 'ISO C 2017' standard
 // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU extensions' standard
+// CHECK-NEXT: note: use 'c2x' for 'Working Draft for ISO C2x' standard
+// CHECK-NEXT: note: use 'gnu2x' for 'Working Draft for ISO C2x with GNU extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}
index f261dee200a766f75f075143461e963191697cf8..97f17ad4e7c1e5f3984b46556effacade01f5001 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
 
 enum [[]] E {
   One [[]],
index 5b537625c1298966921072983a07f151039dc0ed..ec74edf058ef24ac4613172124cae717c9c634da 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c2x %s
 
 struct S {};
 struct S * [[clang::address_space(1)]] Foo;
index 2505f1294c38dfc618c13fbbb21ca7cb1fcf6a9c..744fb1f7c4002309d95fee4bbb74705c2244a74c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fdouble-square-bracket-attributes
+// RUN: %clang_cc1 %s -verify -fsyntax-only --std=c2x
 
 int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
 void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}
index 68150dded9d532bb0cc8f60ae05ba3c6491b9a6a..39ec2da9a152fd7ce82c798d0b90997619cd748a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
 
 struct [[maybe_unused]] S1 { // ok
   int a [[maybe_unused]];
index 816cf7835fa92fae21c4517870562e321ef0edd1..82b9634fc9f39ea5aebafc9de4c26f21fea676c2 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
 
 struct [[maybe_unused]] S1 { // ok
   int a [[maybe_unused]];
index fc5b12347e62c7221c0605e012de030fd3b32e5e..5eaeda40d9bfef75c22d096595d41f99e9a992d9 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
 
 struct [[nodiscard]] S1 { // ok
   int i;