Lexer: always allow imaginary constants in GNU mode.
authorTim Northover <tnorthover@apple.com>
Tue, 8 Aug 2017 22:03:54 +0000 (22:03 +0000)
committerTim Northover <tnorthover@apple.com>
Tue, 8 Aug 2017 22:03:54 +0000 (22:03 +0000)
llvm-svn: 310423

clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/imaginary-constants.cpp [new file with mode: 0644]
clang/test/SemaCXX/constexpr-printing.cpp
clang/unittests/AST/DeclTest.cpp

index a598a46..52b259e 100644 (file)
@@ -659,7 +659,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
         }
       }
       // "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':
diff --git a/clang/test/Lexer/imaginary-constants.cpp b/clang/test/Lexer/imaginary-constants.cpp
new file mode 100644 (file)
index 0000000..3a176be
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++98 -DHAVE_IMAGINARY=1
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++11 -DHAVE_IMAGINARY=1
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++14 -DHAVE_IMAGINARY=1
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -DHAVE_IMAGINARY=0
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -DHAVE_IMAGINARY=0
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 -DHAVE_IMAGINARY=0 -DCXX14=1
+
+// Imaginary constants are a GNU extension that became problematic when C++14
+// defined its own versions. Until then they're supported even in
+// standards-compliant mode.
+#if HAVE_IMAGINARY
+// expected-no-diagnostics
+#elif CXX14
+// expected-error@+9 {{no matching literal operator for call to 'operator""i' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}}
+// expected-error@+9 {{no matching literal operator for call to 'operator""il' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}}
+// expected-error@+9 {{invalid suffix 'ill' on integer constant}}
+#else
+// expected-error@+5 {{invalid suffix 'i' on integer constant}}
+// expected-error@+5 {{invalid suffix 'il' on integer constant}}
+// expected-error@+7 {{invalid suffix 'ill' on integer constant}}
+#endif
+
+_Complex int val1 = 2i;
+_Complex long val2 = 2il;
+_Complex long long val3 = 2ill;
index 7f6a9c6..3112fde 100644 (file)
@@ -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 87aeef4..f06f21a 100644 (file)
@@ -26,7 +26,7 @@ TEST(Decl, CleansUpAPValues) {
   // 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(),