From 17de482e081eca52da08628b5fe276d419bc03a8 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 25 Feb 2016 14:09:18 +0000 Subject: [PATCH] PR c++/68049 * tree.c (strip_typedefs): Use DECL_ORIGINAL_TYPE. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233715 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/tree.c | 10 +++++++++- gcc/testsuite/g++.dg/ext/attribute-may-alias-3.C | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/attribute-may-alias-3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3ae4daf..eb5cfe6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-02-25 Jason Merrill + + PR c++/68049 + * tree.c (strip_typedefs): Use DECL_ORIGINAL_TYPE. + 2016-02-25 Patrick Palka PR c++/69736 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 0f7287a..ac38ce3 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1447,7 +1447,15 @@ strip_typedefs (tree t, bool *remove_attributes) } if (!result) - result = TYPE_MAIN_VARIANT (t); + { + if (typedef_variant_p (t)) + /* Explicitly get the underlying type, as TYPE_MAIN_VARIANT doesn't + strip typedefs with attributes. */ + result = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (t))); + else + result = TYPE_MAIN_VARIANT (t); + } + gcc_assert (!typedef_variant_p (result)); if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result) || TYPE_ALIGN (t) != TYPE_ALIGN (result)) { diff --git a/gcc/testsuite/g++.dg/ext/attribute-may-alias-3.C b/gcc/testsuite/g++.dg/ext/attribute-may-alias-3.C new file mode 100644 index 0000000..ba6091b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attribute-may-alias-3.C @@ -0,0 +1,22 @@ +// PR c++/68049 +// { dg-do compile { target c++11 } } + +template struct Bar +{ + using type = T; +}; +template struct Foo +{ + typedef typename Bar::type alias_type [[gnu::may_alias]]; + + alias_type operator()() { return {}; } +}; + +template void print(T) {} + +int main() +{ + print(Foo()()); + print(0); + return 0; +} -- 2.7.4