Skip to content

Commit 254a5c0

Browse files
committed
Give a diagnostic when using non-POD types in a va_arg
llvm-svn: 132905
1 parent 0ac67fa commit 254a5c0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,6 +3933,9 @@ def warn_second_parameter_of_va_start_not_last_named_argument : Warning<
39333933
"second parameter of 'va_start' not last named argument">;
39343934
def err_first_argument_to_va_arg_not_of_type_va_list : Error<
39353935
"first argument to 'va_arg' is of type %0 and not 'va_list'">;
3936+
def warn_second_parameter_to_va_arg_not_pod : Warning<
3937+
"second argument to 'va_arg' is of non-POD type %0">,
3938+
InGroup<DiagGroup<"non-pod-varargs">>, DefaultError;
39363939

39373940
def warn_return_missing_expr : Warning<
39383941
"non-void %select{function|method}1 %0 should return a value">, DefaultError,

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9819,7 +9819,11 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
98199819
}
98209820

98219821
// FIXME: Check that type is complete/non-abstract
9822-
// FIXME: Warn if a non-POD type is passed in.
9822+
9823+
if (!TInfo->getType()->isDependentType() && !TInfo->getType()->isPODType())
9824+
return ExprError(Diag(TInfo->getTypeLoc().getBeginLoc(),
9825+
diag::warn_second_parameter_to_va_arg_not_pod)
9826+
<< TInfo->getType() << TInfo->getTypeLoc().getSourceRange());
98239827

98249828
QualType T = TInfo->getType().getNonLValueExprType(Context);
98259829
return Owned(new (Context) VAArgExpr(BuiltinLoc, E, TInfo, RPLoc, T));

clang/test/SemaTemplate/instantiate-expr-3.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ struct VaArg1 {
117117

118118
template struct VaArg1<__builtin_va_list, int>;
119119
template struct VaArg1<int, int>; // expected-note{{instantiation}}
120+
121+
struct VaArg2 {
122+
virtual void f(int n, ...) {
123+
__builtin_va_list va;
124+
__builtin_va_start(va, n);
125+
(void)__builtin_va_arg(va, VaArg2); // expected-error {{second argument to 'va_arg' is of non-POD type 'VaArg2'}}
126+
__builtin_va_end(va);
127+
}
128+
};

0 commit comments

Comments
 (0)