re PR c++/79687 (Wrong code with pointer-to-member)

PR c++/79687
	* init.c (constant_value_1): Break if the variable has a dynamic
	initializer.

	* g++.dg/expr/ptrmem8.C: New test.
	* g++.dg/expr/ptrmem9.C: New test.

From-SVN: r246008
This commit is contained in:
Marek Polacek 2017-03-09 16:36:37 +00:00 committed by Marek Polacek
parent d721dc3c4b
commit 6443c7c0e5
5 changed files with 51 additions and 0 deletions

View File

@ -4,6 +4,10 @@
* tree.c (strip_typedefs): Skip the attribute handling if T is
a variant type which hasn't been updated yet.
PR c++/79687 - wrong code with pointer-to-member
* init.c (constant_value_1): Break if the variable has a dynamic
initializer.
2017-03-08 Jason Merrill <jason@redhat.com>
PR c++/79797 - ICE with self-reference in array DMI.

View File

@ -2203,6 +2203,13 @@ constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
if (TREE_CODE (init) == CONSTRUCTOR
&& !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
break;
/* If the variable has a dynamic initializer, don't use its
DECL_INITIAL which doesn't reflect the real value. */
if (VAR_P (decl)
&& TREE_STATIC (decl)
&& !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
&& DECL_NONTRIVIALLY_INITIALIZED_P (decl))
break;
decl = unshare_expr (init);
}
return decl;

View File

@ -1,3 +1,9 @@
2017-03-09 Marek Polacek <polacek@redhat.com>
PR c++/79687
* g++.dg/expr/ptrmem8.C: New test.
* g++.dg/expr/ptrmem9.C: New test.
2017-03-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/79977

View File

@ -0,0 +1,15 @@
// PR c++/79687
// { dg-do run }
struct A
{
char c;
};
int main()
{
char A::* p = &A::c;
static char A::* const q = p;
A a;
return &(a.*q) - &a.c;
}

View File

@ -0,0 +1,19 @@
// PR c++/79687
// { dg-do run }
struct A
{
char c;
};
int main()
{
static char A::* p1 = &A::c;
char A::* const q1 = p1;
char A::* p2 = &A::c;
static char A::* const q2 = p2;
A a;
return (&(a.*q1) - &a.c) || (&(a.*q2) - &a.c);
}