re PR c++/79962 (ICE nonnull_check_p on a function template with a type-dependent attribute nonnull)

PR c++/79962
	PR c++/79984
	* c-attribs.c (handle_nonnull_attribute): Save the result of default
	conversion to the attribute list.

	* c-c++-common/nonnull-3.c: New test.
	* g++.dg/warn/Wnonnull3.C: New test.

From-SVN: r246016
This commit is contained in:
Marek Polacek 2017-03-09 22:45:39 +00:00 committed by Marek Polacek
parent 6579b1563b
commit 822a132cfb
5 changed files with 41 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2017-03-09 Marek Polacek <polacek@redhat.com>
PR c++/79962
PR c++/79984
* c-attribs.c (handle_nonnull_attribute): Save the result of default
conversion to the attribute list.
2017-03-09 Martin Liska <mliska@suse.cz>
* c-ada-spec.c (macro_length): Increment value instead of a pointer.

View File

@ -2813,7 +2813,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
tree arg = TREE_VALUE (args);
if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
&& TREE_CODE (arg) != FUNCTION_DECL)
arg = default_conversion (arg);
TREE_VALUE (args) = arg = default_conversion (arg);
if (!get_nonnull_operand (arg, &arg_num))
{

View File

@ -1,3 +1,10 @@
2017-03-09 Marek Polacek <polacek@redhat.com>
PR c++/79962
PR c++/79984
* c-c++-common/nonnull-3.c: New test.
* g++.dg/warn/Wnonnull3.C: New test.
2017-03-09 Matthew Fortune <matthew.fortune@imgtec.com>
* gcc.target/mips/lxc1-sxc1-1.c: Use -mhard-float.

View File

@ -0,0 +1,11 @@
/* PR c++/79984 */
/* { dg-do compile } */
/* { dg-options "-Wnonnull-compare" } */
enum { r = 1 };
__attribute__ ((nonnull (r))) int
f (int *p)
{
return p == 0; /* { dg-warning "nonnull argument 'p' compared to NULL" } */
}

View File

@ -0,0 +1,15 @@
// PR c++/79962
// { dg-options "-Wnonnull" }
template <class T>
__attribute__ ((__nonnull__ (T::i))) void f (typename T::U) { }
struct S1 { enum { i = 1 }; typedef void* U; };
struct S2 { static const int i = 1; typedef void* U; };
void
g ()
{
f<S1>(0); // { dg-warning "null argument where non-null required" }
f<S2>(0); // { dg-warning "null argument where non-null required" }
}