2017-01-11 Jakub Jelinek <jakub@redhat.com>
+ PR c++/71537
+ * fold-const.c (maybe_nonzero_address): Return 1 for function
+ local objects.
+ (tree_single_nonzero_warnv_p): Don't handle function local objects
+ here.
+
PR c++/72813
* gcc.c (default_compilers): Don't add -o %g.s for -S -save-temps
of c-header.
/* Return a positive integer when the symbol DECL is known to have
a nonzero address, zero when it's known not to (e.g., it's a weak
symbol), and a negative integer when the symbol is not yet in the
- symbol table and so whether or not its address is zero is unknown. */
+ symbol table and so whether or not its address is zero is unknown.
+ For function local objects always return positive integer. */
static int
maybe_nonzero_address (tree decl)
{
if (struct symtab_node *symbol = symtab_node::get_create (decl))
return symbol->nonzero_address ();
+ /* Function local objects are never NULL. */
+ if (DECL_P (decl)
+ && (DECL_CONTEXT (decl)
+ && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
+ && auto_var_in_fn_p (decl, DECL_CONTEXT (decl))))
+ return 1;
+
return -1;
}
if (nonzero_addr >= 0)
return nonzero_addr;
- /* Function local objects are never NULL. */
- if (DECL_P (base)
- && (DECL_CONTEXT (base)
- && TREE_CODE (DECL_CONTEXT (base)) == FUNCTION_DECL
- && auto_var_in_fn_p (base, DECL_CONTEXT (base))))
- return true;
-
/* Constants are never weak. */
if (CONSTANT_CLASS_P (base))
return true;
--- /dev/null
+// PR c++/71537
+// { dg-do compile { target c++14 } }
+
+constexpr bool
+foo ()
+{
+ constexpr int n[42] = { 1 };
+ constexpr int o = n ? 1 : 0;
+ constexpr int p = n + 1 ? 1 : 0;
+ constexpr int q = "abc" + 1 ? 1 : 0;
+ return p + p + q == 3;
+}
+
+static_assert (foo (), "");