From 6b5eceac2e1cb21826aec1d800f8c890a54b4d6b Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 23 May 2017 21:41:49 +0000 Subject: Sema: allow imaginary constants via GNU extension if UDL overloads not present. C++14 added user-defined literal support for complex numbers so that you can write something like "complex val = 2i". However, there is an existing GNU extension supporting this syntax and interpreting the result as a _Complex type. This changes parsing so that such literals are interpreted in terms of C++14's operators if an overload is present but otherwise falls back to the original GNU extension. llvm-svn: 303694 --- clang/lib/Sema/SemaLookup.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'clang/lib/Sema/SemaLookup.cpp') diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 678817f0299..2852ea41631 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -3066,7 +3066,7 @@ Sema::LiteralOperatorLookupResult Sema::LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef ArgTys, bool AllowRaw, bool AllowTemplate, - bool AllowStringTemplate) { + bool AllowStringTemplate, bool DiagnoseMissing) { LookupName(R, S); assert(R.getResultKind() != LookupResult::Ambiguous && "literal operator lookup can't be ambiguous"); @@ -3167,11 +3167,15 @@ Sema::LookupLiteralOperator(Scope *S, LookupResult &R, return LOLR_StringTemplate; // Didn't find anything we could use. - Diag(R.getNameLoc(), diag::err_ovl_no_viable_literal_operator) - << R.getLookupName() << (int)ArgTys.size() << ArgTys[0] - << (ArgTys.size() == 2 ? ArgTys[1] : QualType()) << AllowRaw - << (AllowTemplate || AllowStringTemplate); - return LOLR_Error; + if (DiagnoseMissing) { + Diag(R.getNameLoc(), diag::err_ovl_no_viable_literal_operator) + << R.getLookupName() << (int)ArgTys.size() << ArgTys[0] + << (ArgTys.size() == 2 ? ArgTys[1] : QualType()) << AllowRaw + << (AllowTemplate || AllowStringTemplate); + return LOLR_Error; + } + + return LOLR_ErrorNoDiagnostic; } void ADLResult::insert(NamedDecl *New) { -- cgit v1.2.3