[cfe-commits] r152394 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaOverload.cpp test/CXX/over/over.oper/over.literal/p3.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Fri Mar 9 00:16:23 PST 2012
Author: rsmith
Date: Fri Mar 9 02:16:22 2012
New Revision: 152394
URL: http://llvm.org/viewvc/llvm-project?rev=152394&view=rev
Log:
Literal operators can't have default arguments.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/over/over.oper/over.literal/p3.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=152394&r1=152393&r2=152394&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 9 02:16:22 2012
@@ -4758,6 +4758,8 @@
// C++ literal operators
def err_literal_operator_outside_namespace : Error<
"literal operator %0 must be in a namespace or global scope">;
+def err_literal_operator_default_argument : Error<
+ "literal operator cannot have a default argument">;
// FIXME: This diagnostic sucks
def err_literal_operator_params : Error<
"parameter declaration for literal operator %0 is not valid">;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=152394&r1=152393&r2=152394&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar 9 02:16:22 2012
@@ -9389,6 +9389,19 @@
return true;
}
+ // A parameter-declaration-clause containing a default argument is not
+ // equivalent to any of the permitted forms.
+ for (FunctionDecl::param_iterator Param = FnDecl->param_begin(),
+ ParamEnd = FnDecl->param_end();
+ Param != ParamEnd; ++Param) {
+ if ((*Param)->hasDefaultArg()) {
+ Diag((*Param)->getDefaultArgRange().getBegin(),
+ diag::err_literal_operator_default_argument)
+ << (*Param)->getDefaultArgRange();
+ break;
+ }
+ }
+
StringRef LiteralName
= FnDecl->getDeclName().getCXXLiteralIdentifier()->getName();
if (LiteralName[0] != '_') {
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=152394&r1=152393&r2=152394&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Mar 9 02:16:22 2012
@@ -10911,13 +10911,6 @@
bool HadMultipleCandidates = (CandidateSet.size() > 1);
- // FIXME: Reject default arguments in literal operator definitions. We're not
- // supposed to treat this as ambiguous:
- //
- // int operator"" _x(const char *p);
- // int operator"" _x(const char *p, size_t n = 0);
- // int k = 123_x;
-
// Perform overload resolution. This will usually be trivial, but might need
// to perform substitutions for a literal operator template.
OverloadCandidateSet::iterator Best;
Modified: cfe/trunk/test/CXX/over/over.oper/over.literal/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.oper/over.literal/p3.cpp?rev=152394&r1=152393&r2=152394&view=diff
==============================================================================
--- cfe/trunk/test/CXX/over/over.oper/over.literal/p3.cpp (original)
+++ cfe/trunk/test/CXX/over/over.oper/over.literal/p3.cpp Fri Mar 9 02:16:22 2012
@@ -37,3 +37,4 @@
char operator "" _a(char16_t *, size_t); // expected-error {{parameter}}
char operator "" _a(const char32_t *, size_t, bool = false); // expected-error {{parameter}}
char operator "" _a(const char *, signed long); // expected-error {{parameter}}
+char operator "" _a(const char *, size_t = 0); // expected-error {{default argument}}
More information about the cfe-commits
mailing list