llvm-capstone/clang/test/SemaCXX/nonnull.cpp
Richard Smith 588bd9b7f8 Fix representation of __attribute__((nonnull)) to support correctly modeling
the no-arguments case. Don't expand this to an __attribute__((nonnull(A, B,
C))) attribute, since that does the wrong thing for function templates and
varargs functions.

In passing, fix a grammar error in the diagnostic, a crash if
__attribute__((nonnull(N))) is applied to a varargs function,
a bug where the same null argument could be diagnosed multiple
times if there were multiple nonnull attributes referring to it,
and a bug where nonnull attributes would not be accumulated correctly
across redeclarations.

llvm-svn: 216520
2014-08-27 04:59:42 +00:00

21 lines
569 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
template<int I>
struct TS {
__attribute__((returns_nonnull))
void *value_dependent(void) {
return I; // no-warning
}
__attribute__((returns_nonnull))
void *value_independent(void) {
return 0; // expected-warning {{null returned from function that requires a non-null return value}}
}
};
namespace Template {
template<typename T> __attribute__((nonnull)) void f(T t);
void g() { f((void*)0); } // expected-warning {{null passed to a callee that requires a non-null argument}}
void h() { f(0); }
}