]> granicus.if.org Git - clang/commitdiff
Implement P1668R1
authorErich Keane <erich.keane@intel.com>
Mon, 19 Aug 2019 17:39:59 +0000 (17:39 +0000)
committerErich Keane <erich.keane@intel.com>
Mon, 19 Aug 2019 17:39:59 +0000 (17:39 +0000)
Allow inline assembly statements in unexecuted branches of constexpr
functions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/InitPreprocessor.cpp
lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
test/Lexer/cxx-features.cpp
test/SemaCXX/cxx1z-constexpr-lambdas.cpp

index 51c9606745ed1a403e272e9e6407e6a241764d17..6eafe81e826da095c2abeef395fb2ff56bac6476 100644 (file)
@@ -480,6 +480,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
     Builder.defineMacro("__cpp_user_defined_literals", "200809L");
     Builder.defineMacro("__cpp_lambdas", "200907L");
     Builder.defineMacro("__cpp_constexpr",
+                        LangOpts.CPlusPlus2a ? "201907L" :
                         LangOpts.CPlusPlus17 ? "201603L" :
                         LangOpts.CPlusPlus14 ? "201304L" : "200704");
     Builder.defineMacro("__cpp_range_based_for",
index 09c29851dda1484c9472fd80a0a64fa352947ff0..0f260ab6e91c48cc860e189d39800b419b525bb4 100644 (file)
@@ -1995,6 +1995,9 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
         return false;
     return true;
 
+  case Stmt::GCCAsmStmtClass:
+  case Stmt::MSAsmStmtClass:
+    // C++2a allows inline assembly statements.
   case Stmt::CXXTryStmtClass:
     if (Cxx2aLoc.isInvalid())
       Cxx2aLoc = S->getBeginLoc();
index dd26f69156944bf415e38600a6545c36f1ba0bcd..f72984a6a12077857fa0e8650d1c0f9c707f4bcc 100644 (file)
@@ -136,9 +136,13 @@ constexpr int AllowedStmtsCXX11() {
 }
 
 //  or a compound-statement that does not contain [CXX1Y]
-constexpr int DisallowedStmtsCXX1Y_1() {
+constexpr int DisallowedStmtsCXX1Y_1(bool b) {
   //  - an asm-definition
-  asm("int3"); // expected-error {{statement not allowed in constexpr function}}
+  if (b)
+    asm("int3");
+#if !defined(CXX2A)
+  // expected-error@-2 {{use of this statement in a constexpr function is a C++2a extension}}
+#endif
   return 0;
 }
 constexpr int DisallowedStmtsCXX1Y_2() {
index 75d6e0aa14dd3d452200ecb97227175fc0804333..a8ef6291f4cf8b72e5a94e26f4f78c1783735f74 100644 (file)
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201603)
+#if check(constexpr, 0, 200704, 201304, 201603, 201907)
 #error "wrong value for __cpp_constexpr"
 #endif
 
index 12fbcfcf44a02bc46f71e04d3908bc4247f37394..6c773f225414eacbb67c0d8697c51423c612193a 100644 (file)
@@ -23,7 +23,10 @@ namespace ns1 {
 } // end ns1
 
 namespace ns2 {
-  auto L = [](int I) constexpr { asm("non-constexpr");  }; //expected-error{{not allowed in constexpr function}}
+  auto L = [](int I) constexpr { if (I == 5) asm("non-constexpr");  };
+#if __cpp_constexpr < 201907L
+  //expected-error@-2{{use of this statement in a constexpr function is a C++2a extension}}
+#endif
 } // end ns1
 
 // This is not constexpr until C++20, as the requirements on constexpr