[cfe-commits] r58692 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/default1.cpp
Douglas Gregor
doug.gregor at gmail.com
Tue Nov 4 05:57:52 PST 2008
Author: dgregor
Date: Tue Nov 4 07:57:51 2008
New Revision: 58692
URL: http://llvm.org/viewvc/llvm-project?rev=58692&view=rev
Log:
Now that we have copy initialization support, use it for checking the default arguments
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/default1.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=58692&r1=58691&r2=58692&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Nov 4 07:57:51 2008
@@ -126,22 +126,14 @@
// the same semantic constraints as the initializer expression in
// a declaration of a variable of the parameter type, using the
// copy-initialization semantics (8.5).
- //
- // FIXME: CheckSingleAssignmentConstraints has the wrong semantics
- // for C++ (since we want copy-initialization, not copy-assignment),
- // but we don't have the right semantics implemented yet. Because of
- // this, our error message is also very poor.
- QualType DefaultArgType = DefaultArg->getType();
Expr *DefaultArgPtr = DefaultArg.get();
- AssignConvertType ConvTy = CheckSingleAssignmentConstraints(ParamType,
- DefaultArgPtr);
+ bool DefaultInitFailed = PerformCopyInitialization(DefaultArgPtr, ParamType,
+ "in default argument");
if (DefaultArgPtr != DefaultArg.get()) {
DefaultArg.take();
DefaultArg.reset(DefaultArgPtr);
}
- if (DiagnoseAssignmentResult(ConvTy, DefaultArg->getLocStart(),
- ParamType, DefaultArgType, DefaultArg.get(),
- "in default argument")) {
+ if (DefaultInitFailed) {
return;
}
Modified: cfe/trunk/test/SemaCXX/default1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default1.cpp?rev=58692&r1=58691&r2=58692&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/default1.cpp (original)
+++ cfe/trunk/test/SemaCXX/default1.cpp Tue Nov 4 07:57:51 2008
@@ -15,3 +15,15 @@
struct S { } s;
void i(int = s) { } // expected-error {{incompatible type}}
+
+struct X {
+ X(int);
+};
+
+void j(X x = 17);
+
+struct Y {
+ explicit Y(int);
+};
+
+void k(Y y = 17); // expected-error{{incompatible type in default argument}}
More information about the cfe-commits
mailing list