r249641 - When pretty-printing a C++11 literal operator, don't insert whitespace between
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 7 17:18:00 PDT 2015
Author: rsmith
Date: Wed Oct 7 19:17:59 2015
New Revision: 249641
URL: http://llvm.org/viewvc/llvm-project?rev=249641&view=rev
Log:
When pretty-printing a C++11 literal operator, don't insert whitespace between
the "" and the suffix; that breaks names such as 'operator""if'. For symmetry,
also remove the space between the 'operator' and the '""'.
Modified:
cfe/trunk/lib/AST/DeclarationName.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p12.cpp
cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p2.cpp
cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p5.cpp
cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p7.cpp
cfe/trunk/test/CXX/over/over.oper/over.literal/p2.cpp
cfe/trunk/test/Lexer/hexfloat.cpp
cfe/trunk/test/Parser/cxx11-user-defined-literals.cpp
cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp
cfe/trunk/test/SemaCXX/cxx11-user-defined-literals.cpp
cfe/trunk/test/SemaCXX/literal-operators.cpp
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Wed Oct 7 19:17:59 2015
@@ -182,7 +182,7 @@ raw_ostream &operator<<(raw_ostream &OS,
}
case DeclarationName::CXXLiteralOperatorName:
- return OS << "operator \"\" " << N.getCXXLiteralIdentifier()->getName();
+ return OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName();
case DeclarationName::CXXConversionFunctionName: {
OS << "operator ";
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Wed Oct 7 19:17:59 2015
@@ -1727,7 +1727,7 @@ void StmtPrinter::VisitUserDefinedLitera
assert(Args);
if (Args->size() != 1) {
- OS << "operator \"\" " << Node->getUDSuffix()->getName();
+ OS << "operator\"\"" << Node->getUDSuffix()->getName();
TemplateSpecializationType::PrintTemplateArgumentList(
OS, Args->data(), Args->size(), Policy);
OS << "()";
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Oct 7 19:17:59 2015
@@ -2289,7 +2289,7 @@ bool Parser::ParseUnqualifiedIdOperator(
// This isn't a valid literal-operator-id, but we think we know
// what the user meant. Tell them what they should have written.
SmallString<32> Str;
- Str += "\"\" ";
+ Str += "\"\"";
Str += II->getName();
Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement(
SourceRange(TokLocs.front(), TokLocs.back()), Str);
Modified: cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p12.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p12.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p12.cpp (original)
+++ cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p12.cpp Wed Oct 7 19:17:59 2015
@@ -15,7 +15,7 @@ void *operator""_x(const char*); // #2
void *a = 123_x; // ok, calls #2
int b = u8"\"ÑеÑÑ ð"_x; // ok, calls #1
int c = u8R"("ÑеÑÑ ð)"_x; // ok, calls #1
-int d = "test"_x; // expected-note {{in instantiation of function template specialization 'operator "" _x<char, 't', 'e', 's', 't'>' requested here}}
+int d = "test"_x; // expected-note {{in instantiation of function template specialization 'operator""_x<char, 't', 'e', 's', 't'>' requested here}}
int e = uR"("ÑеÑÑ ð)"_x;
int f = UR"("ÑеÑÑ ð)"_x;
-int g = UR"("ÑеÑÑ_ð)"_x; // expected-note {{in instantiation of function template specialization 'operator "" _x<char32_t, 34, 1090, 1077, 1089, 1090, 95, 65536>' requested here}}
+int g = UR"("ÑеÑÑ_ð)"_x; // expected-note {{in instantiation of function template specialization 'operator""_x<char32_t, 34, 1090, 1077, 1089, 1090, 95, 65536>' requested here}}
Modified: cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p2.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p2.cpp (original)
+++ cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p2.cpp Wed Oct 7 19:17:59 2015
@@ -3,14 +3,14 @@
typedef decltype(sizeof(int)) size_t;
// FIXME: These diagnostics should say 'size_t' instead of 'unsigned long'
-int a = 123_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}}
-int b = 4.2_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'long double' or 'const char *', and no matching literal operator template}}
-int c = "foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned}}
-int d = L"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const wchar_t *' and 'unsigned}}
-int e = u8"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned}}
-int f = u"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char16_t *' and 'unsigned}}
-int g = U"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char32_t *' and 'unsigned}}
-int h = 'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char'}}
-int i = L'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'wchar_t'}}
-int j = u'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char16_t'}}
-int k = U'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char32_t'}}
+int a = 123_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}}
+int b = 4.2_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'long double' or 'const char *', and no matching literal operator template}}
+int c = "foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char *' and 'unsigned}}
+int d = L"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const wchar_t *' and 'unsigned}}
+int e = u8"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char *' and 'unsigned}}
+int f = u"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char16_t *' and 'unsigned}}
+int g = U"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char32_t *' and 'unsigned}}
+int h = 'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char'}}
+int i = L'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'wchar_t'}}
+int j = u'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char16_t'}}
+int k = U'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char32_t'}}
Modified: cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p5.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p5.cpp (original)
+++ cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p5.cpp Wed Oct 7 19:17:59 2015
@@ -6,7 +6,7 @@ int &operator "" _x1 (const char *);
double &operator "" _x1 (const char *, size_t);
double &i1 = "foo"_x1;
double &i2 = u8"foo"_x1;
-double &i3 = L"foo"_x1; // expected-error {{no matching literal operator for call to 'operator "" _x1' with arguments of types 'const wchar_t *' and 'unsigned long'}}
+double &i3 = L"foo"_x1; // expected-error {{no matching literal operator for call to 'operator""_x1' with arguments of types 'const wchar_t *' and 'unsigned long'}}
char &operator "" _x1(const wchar_t *, size_t);
char &i4 = L"foo"_x1; // ok
Modified: cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p7.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p7.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p7.cpp (original)
+++ cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p7.cpp Wed Oct 7 19:17:59 2015
@@ -14,10 +14,10 @@ long double operator "" _w(long double);
std::string operator "" _w(const char16_t*, size_t);
unsigned operator "" _w(const char*);
int main() {
- auto v1 = 1.2_w; // calls operator "" _w(1.2L)
- auto v2 = u"one"_w; // calls operator "" _w(u"one", 3)
- auto v3 = 12_w; // calls operator "" _w("12")
- "two"_w; // expected-error {{no matching literal operator for call to 'operator "" _w' with arguments of types 'const char *' and 'unsigned long'}}
+ auto v1 = 1.2_w; // calls operator""_w(1.2L)
+ auto v2 = u"one"_w; // calls operator""_w(u"one", 3)
+ auto v3 = 12_w; // calls operator""_w("12")
+ "two"_w; // expected-error {{no matching literal operator for call to 'operator""_w' with arguments of types 'const char *' and 'unsigned long'}}
same_type<decltype(v1), long double> test1;
same_type<decltype(v2), std::string> test2;
Modified: cfe/trunk/test/CXX/over/over.oper/over.literal/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.oper/over.literal/p2.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/CXX/over/over.oper/over.literal/p2.cpp (original)
+++ cfe/trunk/test/CXX/over/over.oper/over.literal/p2.cpp Wed Oct 7 19:17:59 2015
@@ -37,7 +37,7 @@ template void operator "" _h<'a', 'b', '
namespace rdar13605348 {
class C {
- double operator"" _x(long double value) { return double(value); } // expected-error{{literal operator 'operator "" _x' must be in a namespace or global scope}}
+ double operator"" _x(long double value) { return double(value); } // expected-error{{literal operator 'operator""_x' must be in a namespace or global scope}}
double value() { return 3.2_x; } // expected-error{{no matching literal operator for call to}}
};
Modified: cfe/trunk/test/Lexer/hexfloat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/hexfloat.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/hexfloat.cpp (original)
+++ cfe/trunk/test/Lexer/hexfloat.cpp Wed Oct 7 19:17:59 2015
@@ -12,4 +12,4 @@ double h = 0x1.p2; // expected-warning{{
double i = 0p+3; // expected-error{{invalid suffix 'p' on integer constant}}
#define PREFIX(x) foo ## x
double foo0p = 1, j = PREFIX(0p+3); // ok
-double k = 0x42_amp+3; // expected-error-re{{{{invalid suffix '_amp' on integer constant|no matching literal operator for call to 'operator "" _amp'}}}}
+double k = 0x42_amp+3; // expected-error-re{{{{invalid suffix '_amp' on integer constant|no matching literal operator for call to 'operator""_amp'}}}}
Modified: cfe/trunk/test/Parser/cxx11-user-defined-literals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx11-user-defined-literals.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx11-user-defined-literals.cpp (original)
+++ cfe/trunk/test/Parser/cxx11-user-defined-literals.cpp Wed Oct 7 19:17:59 2015
@@ -77,21 +77,21 @@ const char *p =
erk
flux
)x" "eep\x1f"\
-_no_such_suffix // expected-error {{'operator "" _no_such_suffix'}}
+_no_such_suffix // expected-error {{'operator""_no_such_suffix'}}
"and a bit more"
"and another suffix"_no_such_suffix;
char c =
'\x14'\
-_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
+_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}
int &r =
1234567\
-_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
+_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}
int k =
1234567.89\
-_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
+_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}
// Make sure we handle more interesting ways of writing a string literal which
// is "" in translation phase 7.
@@ -115,15 +115,15 @@ void operator "" u8"" "\u0123" "hello"_a
// Make sure we treat UCNs and UTF-8 as equivalent.
int operator""_µs(unsigned long long) {} // expected-note {{previous}}
int hundred_µs = 50_µs + 50_\u00b5s;
-int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator "" _µs'}}
+int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator""_µs'}}
int operator""_\U0000212B(long double) {} // expected-note {{previous}}
int hundred_â« = 50.0_â« + 50._\U0000212B;
-int operator""_â«(long double) {} // expected-error {{redefinition of 'operator "" _â«'}}
+int operator""_â«(long double) {} // expected-error {{redefinition of 'operator""_â«'}}
int operator""_ð(char) {} // expected-note {{previous}}
int ð = '4'_ð + '2'_\U00010000;
-int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator "" _ð'}}
+int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator""_ð'}}
// These all declare the same function.
int operator""_â®""_\u212e""_\U0000212e""(const char*, size_t);
Modified: cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp Wed Oct 7 19:17:59 2015
@@ -1,21 +1,21 @@
// RUN: %clang_cc1 -std=c++11 -ast-print %s | FileCheck %s
-// CHECK: auto operator "" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr);
+// CHECK: auto operator""_foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr);
auto operator"" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr);
-// CHECK: decltype(""_foo) operator "" _bar(unsigned long long);
+// CHECK: decltype(""_foo) operator""_bar(unsigned long long);
decltype(""_foo) operator"" _bar(unsigned long long);
-// CHECK: decltype(42_bar) operator "" _baz(long double);
+// CHECK: decltype(42_bar) operator""_baz(long double);
decltype(42_bar) operator"" _baz(long double);
-// CHECK: decltype(4.5_baz) operator "" _baz(char);
+// CHECK: decltype(4.5_baz) operator""_baz(char);
decltype(4.5_baz) operator"" _baz(char);
-// CHECK: const char *operator "" _quux(const char *);
+// CHECK: const char *operator""_quux(const char *);
const char *operator"" _quux(const char *);
-// CHECK: template <char ...> const char *operator "" _fritz();
+// CHECK: template <char ...> const char *operator""_fritz();
template<char...> const char *operator"" _fritz();
// CHECK: const char *p1 = "bar1"_foo;
@@ -40,7 +40,7 @@ const char *p9 = 0x42e3F_fritz;
const char *p10 = 3.300e+15_fritz;
template <class C, C...> const char *operator"" _suffix();
-// CHECK: const char *PR23120 = operator "" _suffix<char32_t, 66615>();
+// CHECK: const char *PR23120 = operator""_suffix<char32_t, 66615>();
const char *PR23120 = U"ð·"_suffix;
// CHECK: ;
Modified: cfe/trunk/test/SemaCXX/cxx11-user-defined-literals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-user-defined-literals.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-user-defined-literals.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-user-defined-literals.cpp Wed Oct 7 19:17:59 2015
@@ -70,7 +70,7 @@ namespace Using {
namespace M {
int operator"" _using(char);
}
- int k1 = 'x'_using; // expected-error {{no matching literal operator for call to 'operator "" _using'}}
+ int k1 = 'x'_using; // expected-error {{no matching literal operator for call to 'operator""_using'}}
using M::operator "" _using;
int k2 = 'x'_using;
@@ -80,7 +80,7 @@ namespace AmbiguousRawTemplate {
int operator"" _ambig1(const char *); // expected-note {{candidate}}
template<char...> int operator"" _ambig1(); // expected-note {{candidate}}
- int k1 = 123_ambig1; // expected-error {{call to 'operator "" _ambig1' is ambiguous}}
+ int k1 = 123_ambig1; // expected-error {{call to 'operator""_ambig1' is ambiguous}}
namespace Inner {
template<char...> int operator"" _ambig2(); // expected-note 3{{candidate}}
@@ -88,7 +88,7 @@ namespace AmbiguousRawTemplate {
int operator"" _ambig2(const char *); // expected-note 3{{candidate}}
using Inner::operator"" _ambig2;
- int k2 = 123_ambig2; // expected-error {{call to 'operator "" _ambig2' is ambiguous}}
+ int k2 = 123_ambig2; // expected-error {{call to 'operator""_ambig2' is ambiguous}}
namespace N {
using Inner::operator"" _ambig2;
@@ -133,13 +133,13 @@ namespace Namespace {
int k = _x(); // expected-error {{undeclared identifier '_x'}}
int _y(unsigned long long);
- int k2 = 123_y; // expected-error {{no matching literal operator for call to 'operator "" _y'}}
+ int k2 = 123_y; // expected-error {{no matching literal operator for call to 'operator""_y'}}
}
namespace PR14950 {
template<...> // expected-error {{expected template parameter}}
int operator"" _b(); // expected-error {{no function template matches function template specialization}}
- int main() { return 0_b; } // expected-error {{no matching literal operator for call to 'operator "" _b'}}
+ int main() { return 0_b; } // expected-error {{no matching literal operator for call to 'operator""_b'}}
}
namespace bad_names {
Modified: cfe/trunk/test/SemaCXX/literal-operators.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/literal-operators.cpp?rev=249641&r1=249640&r2=249641&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/literal-operators.cpp (original)
+++ cfe/trunk/test/SemaCXX/literal-operators.cpp Wed Oct 7 19:17:59 2015
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
#include <stddef.h>
struct tag {
- void operator "" _tag_bad (const char *); // expected-error {{literal operator 'operator "" _tag_bad' must be in a namespace or global scope}}
+ void operator "" _tag_bad (const char *); // expected-error {{literal operator 'operator""_tag_bad' must be in a namespace or global scope}}
friend void operator "" _tag_good (const char *);
};
@@ -35,10 +35,14 @@ typedef const char c;
void operator "" _good (c*);
// Check extra cv-qualifiers
-void operator "" _cv_good (volatile const char *, const size_t); // expected-error {{parameter declaration for literal operator 'operator "" _cv_good' is not valid}}
+void operator "" _cv_good (volatile const char *, const size_t); // expected-error {{parameter declaration for literal operator 'operator""_cv_good' is not valid}}
// Template declaration
template <char...> void operator "" _good ();
// FIXME: Test some invalid decls that might crop up.
-template <typename...> void operator "" _invalid(); // expected-error {{parameter declaration for literal operator 'operator "" _invalid' is not valid}}
+template <typename...> void operator "" _invalid(); // expected-error {{parameter declaration for literal operator 'operator""_invalid' is not valid}}
+
+_Complex float operator""if(long double); // expected-warning {{reserved}}
+_Complex float test_if_1() { return 2.0f + 1.5if; };
+void test_if_2() { "foo"if; } // expected-error {{no matching literal operator for call to 'operator""if'}}
More information about the cfe-commits
mailing list