--- /dev/null
+// Test that we handle mangling of statics in inlines properly.
+// { dg-options -fno-weak }
+// { dg-do run }
+
+inline int f ()
+{
+ static int nested;
+ nested = 24;
+ {
+ static int nested;
+ nested = 42;
+ }
+ return (nested != 24);
+}
+
+int main()
+{
+ return f ();
+}
--- /dev/null
+// Test that 'extern template' suppresses instantiations.
+// { dg-do link }
+// { dg-options "" }
+
+template <class T> void f (T) { }
+extern template void f (int);
+
+template <class T> struct A {
+ void f ();
+};
+template <class T> void A<T>::f () { }
+extern template struct A<int>;
+
+// { dg-error "void f<int>\\(int\\)" "suppressing f<int>" { target *-*-* } "0" }
+void test_f_int () { f(42); }
+
+// { dg-error "A<int>::f\\(\\)" "suppressing A<int>" { target *-*-* } "0" }
+void test_A_int_f () { A<int> a; a.f (); }
+
+// { dg-bogus "void f<double>\\(double\\)" "f<double>" { target *-*-* } "0" }
+void test_f_double () { f (2.0); }
+
+// { dg-bogus "A<double>::f\\(\\)" "A<double>" { target *-*-* } "0" }
+void test_A_double_f () { A<double> b; b.f (); }
+
+int main ()
+{
+ test_f_int ();
+ test_A_int_f ();
+ test_f_double ();
+ test_A_double_f ();
+}
--- /dev/null
+// Test that we complain about the gcc cast-as-lvalue extension.
+
+int main ()
+{
+ char c;
+
+ static_cast<int>(c) = 2; // { dg-error "lvalue" "not an lvalue" }
+
+ return c != 2;
+}
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options -Wredundant-decls } */
-
-/* Test to see if spurious warnings about redundant
- declarations are emiited because of the friend
- declaration. */
-
-class Foo
-{
- friend void bar (Foo);
-public:
-};
-
-extern void bar (Foo);
--- /dev/null
+// Test for the named return value optimization.
+// { dg-do run }
+// { dg-options -fno-inline }
+
+int c;
+int d;
+
+struct A
+{
+ A() { ++c; }
+ A(const A&) { ++c; };
+ ~A() { ++d; }
+};
+
+inline A f ()
+{
+ A a;
+ return a;
+}
+
+int main ()
+{
+ {
+ A a = f ();
+ }
+
+ return !(c == 1 && c == d);
+}
--- /dev/null
+// Submitted by Erik Rozendaal <dlr@acm.org>
+// Test case for GNATS bug 787.
+// { dg-do run }
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static int calls;
+
+int &foo (int &arg)
+{
+ calls++;
+ arg=0;
+ return arg;
+}
+
+int &identity (int &x)
+{
+ return x;
+}
+
+int main()
+{
+ int a;
+
+ calls = 0;
+ int &b = ++foo (a);
+ if (calls > 1)
+ abort ();
+ if (&a != &b)
+ abort ();
+ if (a != 1)
+ abort ();
+
+ calls = 0;
+ int &c = ++identity (++foo (a));
+ if (calls > 1)
+ abort ();
+ if (&a != &c)
+ abort ();
+ if (a != 2)
+ abort ();
+
+ exit (0);
+}
--- /dev/null
+// Submitted by Jason Merrill <jason_merrill@redhat.com>
+// Test for proper handling of local static references.
+// { dg-do run }
+
+int r;
+
+int c;
+int f ()
+{
+ // Test that we only initialize i once.
+ if (++c > 1)
+ ++r;
+ return 42;
+}
+
+const int *p;
+void g ()
+{
+ static const int &i = f();
+
+ // Test that i points to the same place in both calls.
+ if (p && p != &i)
+ ++r;
+ // Test that if so, it points to static data.
+ if (i != 42)
+ ++r;
+
+ p = &i;
+}
+
+void h ()
+{
+ int arr[] = { 1, 1, 1, 1, 1, 1, 1 };
+ g ();
+}
+
+int main ()
+{
+ g ();
+ h ();
+ return r;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options -pedantic } */
+
+/* test of 'true' and 'false' in #if. this is accepted with a pedwarn
+ before stdbool.h is included, silently afterward. */
+
+/* Make sure they're viable keywords. */
+bool a = true;
+bool b = false;
+
+#if true /* { dg-warning "true" "true in #if pedwarn" } */
+#else
+#error true is false /* { dg-bogus "true" "true is false" } */
+#endif
+
+#if false /* { dg-warning "false" "false in #if pedwarn" } */
+#error false is true /* { dg-bogus "false" "false is true" } */
+#endif
+
+#include <stdbool.h>
+
+/* Must still be viable keywords. */
+bool c = true;
+bool d = false;
+
+#if true /* { dg-bogus "true" "true in #if with stdbool.h" } */
+#else
+#error true is false /* { dg-bogus "true" "true is false" } */
+#endif
+
+#if false /* { dg-bogus "false" "false in #if with stdbool.h" } */
+#error false is true /* { dg-bogus "false" "false is true" } */
+#endif
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options -pedantic } */
-
-/* test of 'true' and 'false' in #if. this is accepted with a pedwarn
- before stdbool.h is included, silently afterward. */
-
-/* Make sure they're viable keywords. */
-bool a = true;
-bool b = false;
-
-#if true /* { dg-warning "true" "true in #if pedwarn" } */
-#else
-#error true is false /* { dg-bogus "true" "true is false" } */
-#endif
-
-#if false /* { dg-warning "false" "false in #if pedwarn" } */
-#error false is true /* { dg-bogus "false" "false is true" } */
-#endif
-
-#include <stdbool.h>
-
-/* Must still be viable keywords. */
-bool c = true;
-bool d = false;
-
-#if true /* { dg-bogus "true" "true in #if with stdbool.h" } */
-#else
-#error true is false /* { dg-bogus "true" "true is false" } */
-#endif
-
-#if false /* { dg-bogus "false" "false in #if with stdbool.h" } */
-#error false is true /* { dg-bogus "false" "false is true" } */
-#endif
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options -Wredundant-decls } */
+
+/* Test to see if spurious warnings about redundant
+ declarations are emiited because of the friend
+ declaration. */
+
+class Foo
+{
+ friend void bar (Foo);
+public:
+};
+
+extern void bar (Foo);