diff options
| author | David Blaikie <dblaikie@gmail.com> | 2012-08-08 17:33:31 +0000 |
|---|---|---|
| committer | David Blaikie <dblaikie@gmail.com> | 2012-08-08 17:33:31 +0000 |
| commit | 1c7c8f763769d7d98b8ef7538693f7d99be3cedd (patch) | |
| tree | eae471efe22aa10e1875415c0d68f9b1c0cf57a2 /clang/test/SemaCXX/constant-expression-cxx11.cpp | |
| parent | a5063a620847de422e64c330ed5d07718583bf9c (diff) | |
| download | bcm5719-llvm-1c7c8f763769d7d98b8ef7538693f7d99be3cedd.tar.gz bcm5719-llvm-1c7c8f763769d7d98b8ef7538693f7d99be3cedd.zip | |
Implement warning for integral null pointer constants other than the literal 0.
This is effectively a warning for code that violates core issue 903 & thus will
become standard error in the future, hopefully. It catches strange null
pointers such as: '\0', 1 - 1, const int null = 0; etc...
There's currently a flaw in this warning (& the warning for 'false' as a null
pointer literal as well) where it doesn't trigger on comparisons (ptr == '\0'
for example). Fix to come in a future patch.
Also, due to this only being a warning, not an error, it triggers quite
frequently on gtest code which tests expressions for null-pointer-ness in a
SFINAE context (so it wouldn't be a problem if this was an error as in an
actual implementation of core issue 903). To workaround this for now, the
diagnostic does not fire in unevaluated contexts.
Review by Sean Silva and Richard Smith.
llvm-svn: 161501
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx11.cpp')
| -rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 0b7a6555e06..a3ead79a845 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -710,10 +710,16 @@ static_assert(&ok2 == pok2, ""); static_assert((Base2*)(Derived*)(Base*)pb1 == pok2, ""); static_assert((Derived*)(Base*)pb1 == (Derived*)pok2, ""); -constexpr Base *nullB = 42 - 6 * 7; +constexpr Base *nullB = 42 - 6 * 7; // expected-warning {{expression which evaluates to zero treated as a null pointer constant of type 'Class::Base *const'}} static_assert((Bottom*)nullB == 0, ""); static_assert((Derived*)nullB == 0, ""); static_assert((void*)(Bottom*)nullB == (void*)(Derived*)nullB, ""); +Base * nullB2 = '\0'; // expected-warning {{expression which evaluates to zero treated as a null pointer constant of type 'Class::Base *'}} +Base * nullB3 = (0); +// We suppress the warning in unevaluated contexts to workaround some gtest +// behavior. Once this becomes an error this isn't a problem anymore. +static_assert(nullB == (1 - 1), ""); + namespace ConversionOperators { |

