mirror of https://github.com/microsoft/clang.git
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 '""'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249641 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f04251164b
commit
a2ce7ac7a5
|
@ -182,7 +182,7 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
|
|||
}
|
||||
|
||||
case DeclarationName::CXXLiteralOperatorName:
|
||||
return OS << "operator \"\" " << N.getCXXLiteralIdentifier()->getName();
|
||||
return OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName();
|
||||
|
||||
case DeclarationName::CXXConversionFunctionName: {
|
||||
OS << "operator ";
|
||||
|
|
|
@ -1727,7 +1727,7 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
|
|||
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 << "()";
|
||||
|
|
|
@ -2289,7 +2289,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
|
|||
// 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);
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -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'}}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -37,7 +37,7 @@ template void operator "" _h<'a', 'b', 'c', 'd'>();
|
|||
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}}
|
||||
};
|
||||
|
||||
|
|
|
@ -12,4 +12,4 @@ double h = 0x1.p2; // expected-warning{{hexadecimal floating constants are a C99
|
|||
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'}}}}
|
||||
|
|
|
@ -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"_all_of_the_things ""(const char*); // exp
|
|||
// 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);
|
||||
|
|
|
@ -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: ;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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'}}
|
||||
|
|
Loading…
Reference in New Issue