[PATCH] D33424: Lexer: allow imaginary constants in GNU mode (only).

Tim Northover via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 15:29:27 PDT 2017


t.p.northover created this revision.
Herald added a subscriber: mcrosier.

While looking into the regression tests' compatibility with C++14, many of the failures were because that specification defined UDLs for imaginary constants, specifically ones ending in 'i' and 'il'. This conflicted with the previous GNU extension that allowed them purely as a builtin literal syntax so they'd been disabled in C++14 mode.

GCC's behaviour is to use the builtin constants in all "-std=gnu++N" modes but disable them for "-std=c++11" and "-std=c++14" (they are still permitted in "-std=c++98"). This seemed inconsistent (and likely an implementation detail rather than intended behaviour) so my patch makes the decision purely on whether we're in GNU mode.

Does it look reasonable?

Tim.


https://reviews.llvm.org/D33424

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/SemaCXX/constexpr-printing.cpp
  clang/unittests/AST/DeclTest.cpp


Index: clang/unittests/AST/DeclTest.cpp
===================================================================
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -26,7 +26,7 @@
   // This is a regression test for a memory leak in APValues for structs that
   // allocate memory. This test only fails if run under valgrind with full leak
   // checking enabled.
-  std::vector<std::string> Args(1, "-std=c++11");
+  std::vector<std::string> Args(1, "-std=gnu++11");
   Args.push_back("-fno-ms-extensions");
   ASSERT_TRUE(runToolOnCodeWithArgs(
       Factory->create(),
Index: clang/test/SemaCXX/constexpr-printing.cpp
===================================================================
--- clang/test/SemaCXX/constexpr-printing.cpp
+++ clang/test/SemaCXX/constexpr-printing.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify -triple x86_64-linux-gnu
+// RUN: %clang_cc1 %s -std=gnu++11 -fsyntax-only -verify -triple x86_64-linux-gnu
 
 struct S;
 constexpr int extract(const S &s);
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -653,7 +653,7 @@
         }
       }
       // "i", "if", and "il" are user-defined suffixes in C++1y.
-      if (*s == 'i' && PP.getLangOpts().CPlusPlus14)
+      if (*s == 'i' && !PP.getLangOpts().GNUMode)
         break;
       // fall through.
     case 'j':


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33424.99824.patch
Type: text/x-patch
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170522/d7037ac9/attachment.bin>


More information about the cfe-commits mailing list