aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-04 13:57:51 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-04 13:57:51 +0000
commiteb704f22ef00a2b41ff1ccf1b20016d7cd4c5c85 (patch)
tree75958f8d325575b8c11e388eff81f4c0bb79293c
parent3996f23ac20de411e0b5931a451bd05142f0b712 (diff)
Now that we have copy initialization support, use it for checking the default arguments
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58692 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclCXX.cpp14
-rw-r--r--test/SemaCXX/default1.cpp12
2 files changed, 15 insertions, 11 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index bd3da49030..33fc52b71d 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -126,22 +126,14 @@ Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc,
// 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;
}
diff --git a/test/SemaCXX/default1.cpp b/test/SemaCXX/default1.cpp
index fe019c847a..3acf119265 100644
--- a/test/SemaCXX/default1.cpp
+++ b/test/SemaCXX/default1.cpp
@@ -15,3 +15,15 @@ void h(int i, int j = 2, int k = 3,
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}}