public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/45267 (always_inline sorry in 4.5)
@ 2011-04-20  1:06 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-04-20  1:06 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

duplicate_decls was dropping DECL_DISREGARD_INLINE_LIMITS, but leaving 
the always_inline attribute in DECL_ATTRIBUTES, leading to confusion. 
This patch keeps them in sync.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.5 (not 4.6).

[-- Attachment #2: 45267.patch --]
[-- Type: text/plain, Size: 1707 bytes --]

commit 679e5e90918506d6792b8c0b19deff0f1a497298
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 18 17:35:35 2011 -0700

    	PR c++/45267
    	* decl.c (duplicate_decls): Keep always_inline attribute
    	in sync with DECL_DISREGARD_INLINE_LIMITS.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 794832b..6309648 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2052,6 +2052,19 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
 
 	  /* [temp.expl.spec/14] We don't inline explicit specialization
 	     just because the primary template says so.  */
+
+	  /* But still keep DECL_DISREGARD_INLINE_LIMITS in sync with
+	     the always_inline attribute.  */
+	  if (DECL_DISREGARD_INLINE_LIMITS (olddecl)
+	      && !DECL_DISREGARD_INLINE_LIMITS (newdecl))
+	    {
+	      if (DECL_DECLARED_INLINE_P (newdecl))
+		DECL_DISREGARD_INLINE_LIMITS (newdecl) = true;
+	      else
+		DECL_ATTRIBUTES (newdecl)
+		  = remove_attribute ("always_inline",
+				      DECL_ATTRIBUTES (newdecl));
+	    }
 	}
       else if (new_defines_function && DECL_INITIAL (olddecl))
 	{
diff --git a/gcc/testsuite/g++.dg/ext/attrib41.C b/gcc/testsuite/g++.dg/ext/attrib41.C
new file mode 100644
index 0000000..368554a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib41.C
@@ -0,0 +1,19 @@
+// PR c++/45267
+// { dg-options "-O" }
+
+template<typename T> struct Vector {
+  Vector(long long x);
+  inline Vector<T> operator<<(int x) const __attribute__((always_inline));
+};
+long long bar (long long);
+template<> inline Vector<int> Vector<int>::operator<<(int x) const {
+  return bar(x);
+}
+bool b;
+int main() {
+  Vector<int> a(1);
+  if ((a << 2), b) {
+    a << 2;
+    throw 1;
+  }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-20  0:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20  1:06 C++ PATCH for c++/45267 (always_inline sorry in 4.5) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).