From: Douglas Gregor Date: Fri, 14 Oct 2011 20:34:19 +0000 (+0000) Subject: Don't try to diagnose anything when we're passing incomplete types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8e778da8545624826440366a709d555332ffc73;p=clang Don't try to diagnose anything when we're passing incomplete types through varargs. This only happens when we're in an unevaluated context, where we don't want to trigger an error anyway. Fixes PR11131 / . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141986 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 97060772b0..41fcf7299d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -523,7 +523,10 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, << E->getType() << CT)) return ExprError(); - if (!E->getType().isPODType(Context)) { + // Complain about passing non-POD types through varargs. However, don't + // perform this check for incomplete types, which we can get here when we're + // in an unevaluated context. + if (!E->getType()->isIncompleteType() && !E->getType().isPODType(Context)) { // 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, diff --git a/test/CXX/expr/expr.post/expr.call/p7-0x.cpp b/test/CXX/expr/expr.post/expr.call/p7-0x.cpp index e6ffebc8d8..d51ba09835 100644 --- a/test/CXX/expr/expr.post/expr.call/p7-0x.cpp +++ b/test/CXX/expr/expr.post/expr.call/p7-0x.cpp @@ -15,3 +15,16 @@ void f(X1 x1, X2 x2) { vararg(x1); // okay vararg(x2); // expected-error{{cannot pass object of non-trivial type 'X2' through variadic function; call will abort at runtime}} } + + +namespace PR11131 { + struct S; + + S &getS(); + + void f(...); + + void g() { + (void)sizeof(f(getS())); + } +} diff --git a/test/SemaCXX/vararg-non-pod.cpp b/test/SemaCXX/vararg-non-pod.cpp index 3ca07b0215..42c27fb30e 100644 --- a/test/SemaCXX/vararg-non-pod.cpp +++ b/test/SemaCXX/vararg-non-pod.cpp @@ -118,4 +118,3 @@ void t8(int n, ...) { (void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}} __builtin_va_end(list); } -