[cfe-commits] r132905 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaTemplate/instantiate-expr-3.cpp
David Majnemer
david.majnemer at gmail.com
Sun Jun 12 23:37:03 PDT 2011
Author: majnemer
Date: Mon Jun 13 01:37:03 2011
New Revision: 132905
URL: http://llvm.org/viewvc/llvm-project?rev=132905&view=rev
Log:
Give a diagnostic when using non-POD types in a va_arg
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=132905&r1=132904&r2=132905&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 13 01:37:03 2011
@@ -3933,6 +3933,9 @@
"second parameter of 'va_start' not last named argument">;
def err_first_argument_to_va_arg_not_of_type_va_list : Error<
"first argument to 'va_arg' is of type %0 and not 'va_list'">;
+def warn_second_parameter_to_va_arg_not_pod : Warning<
+ "second argument to 'va_arg' is of non-POD type %0">,
+ InGroup<DiagGroup<"non-pod-varargs">>, DefaultError;
def warn_return_missing_expr : Warning<
"non-void %select{function|method}1 %0 should return a value">, DefaultError,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=132905&r1=132904&r2=132905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 13 01:37:03 2011
@@ -9819,7 +9819,11 @@
}
// FIXME: Check that type is complete/non-abstract
- // FIXME: Warn if a non-POD type is passed in.
+
+ if (!TInfo->getType()->isDependentType() && !TInfo->getType()->isPODType())
+ return ExprError(Diag(TInfo->getTypeLoc().getBeginLoc(),
+ diag::warn_second_parameter_to_va_arg_not_pod)
+ << TInfo->getType() << TInfo->getTypeLoc().getSourceRange());
QualType T = TInfo->getType().getNonLValueExprType(Context);
return Owned(new (Context) VAArgExpr(BuiltinLoc, E, TInfo, RPLoc, T));
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp?rev=132905&r1=132904&r2=132905&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Mon Jun 13 01:37:03 2011
@@ -117,3 +117,12 @@
template struct VaArg1<__builtin_va_list, int>;
template struct VaArg1<int, int>; // expected-note{{instantiation}}
+
+struct VaArg2 {
+ virtual void f(int n, ...) {
+ __builtin_va_list va;
+ __builtin_va_start(va, n);
+ (void)__builtin_va_arg(va, VaArg2); // expected-error {{second argument to 'va_arg' is of non-POD type 'VaArg2'}}
+ __builtin_va_end(va);
+ }
+};
More information about the cfe-commits
mailing list