summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-05-21 16:27:21 +0000
committerDouglas Gregor <dgregor@apple.com>2011-05-21 16:27:21 +0000
commit253cadfe681611bebb1addc47911b2f3f2bc2088 (patch)
treec28b46c9f58b55118d9aa6690a96528c10895332 /clang/lib
parent8e8f59bdfbbcde8c6bcee4774ae337bcdd9647a1 (diff)
downloadbcm5719-llvm-253cadfe681611bebb1addc47911b2f3f2bc2088.tar.gz
bcm5719-llvm-253cadfe681611bebb1addc47911b2f3f2bc2088.zip
Implement C++0x semantics for passing non-POD classes through varargs.
llvm-svn: 131792
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5afd263ea13..6bccdaeb246 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -455,12 +455,32 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
<< E->getType() << CT))
return ExprError();
- if (!E->getType()->isPODType() &&
- DiagRuntimeBehavior(E->getLocStart(), 0,
+ // C++ [expr.call]p7 prohibits non-POD types.
+ if (!E->getType()->isPODType()) {
+ // C++0x [expr.call]p7:
+ // Passing a potentially-evaluated argument of class type (Clause 9)
+ // having a non-trivial copy constructor, a non-trivial move constructor,
+ // or a non-trivial destructor, with no corresponding parameter,
+ // is conditionally-supported with implementation-defined semantics.
+ bool TrivialEnough = false;
+ if (getLangOptions().CPlusPlus0x && !E->getType()->isDependentType()) {
+ if (CXXRecordDecl *Record = E->getType()->getAsCXXRecordDecl()) {
+ if (Record->hasTrivialCopyConstructor() &&
+ Record->hasTrivialMoveConstructor() &&
+ Record->hasTrivialDestructor())
+ TrivialEnough = true;
+ }
+ }
+
+ if (TrivialEnough) {
+ // Nothing to diagnose. This is okay.
+ } else if (DiagRuntimeBehavior(E->getLocStart(), 0,
PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
- << E->getType() << CT))
- return ExprError();
-
+ << getLangOptions().CPlusPlus0x << E->getType()
+ << CT))
+ return ExprError();
+ }
+
return Owned(E);
}
OpenPOWER on IntegriCloud