@@ -1,22 +1,79 @@
/* { dg-options "-Wunused-variable" } */
+/* Verify that ignoring -Wunused-variable works, for various placements
+ of the variable and the _Pragma. */
+
+/* Test 1: the _Pragma is in a macro, but the affected code isn't. */
+
+#pragma GCC diagnostic push
+
+#define MACRO_1 \
+ _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+
+int test_1()
+{
+ _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+ int x;
+ return 0;
+}
+#pragma GCC diagnostic pop
+
+
+/* Test 2: neither the _Pragma nor the affected code are in a macro. */
+
+#pragma GCC diagnostic push
+int test_2()
+{
+ _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+ int x;
+ return 0;
+}
+#pragma GCC diagnostic pop
+
+
+/* Test 3: the _Pragma isn't in a macro, but the affected code is. */
+
+#define MACRO_3 \
+ int x;
+
#pragma GCC diagnostic push
-int f()
+int test_3()
{
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+ MACRO_3
+ return 0;
+}
+#pragma GCC diagnostic pop
+
+
+/* Test 4: the _Pragma and the affected code are in different macros. */
+
+#pragma GCC diagnostic push
+#define MACRO_4A \
+ _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+
+#define MACRO_4B \
int x;
+
+int test_4()
+{
+ MACRO_4A;
+ MACRO_4B
return 0;
}
#pragma GCC diagnostic pop
+
+/* Test 5: both the _Pragma and the affected code are in the same macro. */
+
#pragma GCC diagnostic push
-#define MACRO \
+#define MACRO_5 \
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \
int x;
-int g()
+int test_5()
{
- MACRO;
+ MACRO_5;
return 0;
}
#pragma GCC diagnostic pop
new file mode 100644
@@ -0,0 +1,21 @@
+/* { dg-options "-Wuninitialized" } */
+
+/* Verify disabling a warning, where the _Pragma is within
+ a macro, but the affected code is *not* in a macro. */
+
+/* TODO: XFAIL: why does g++ still emit a warning here? (works for C). */
+
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+
+void test (char yylval)
+{
+ char *yyvsp;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail { c++ } } } */
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-options "-Wuninitialized" } */
+
+/* Verify disabling a warning, where both the _Pragma and the
+ affected code are *not* in a macro. */
+
+void test (char yylval)
+{
+ char *yyvsp;
+ _Pragma ("GCC diagnostic push")
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+ *++yyvsp = yylval;
+ _Pragma ("GCC diagnostic pop")
+}
new file mode 100644
@@ -0,0 +1,20 @@
+/* { dg-options "-Wuninitialized" } */
+
+/* Verify disabling a warning, where the _Pragma is in regular code,
+ but the affected code is within a macro. */
+
+/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning
+ The warning is reported at the macro definition location, rather than
+ the macro expansion location. */
+
+#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */
+
+void test (char yylval)
+{
+ char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */
+ _Pragma ("GCC diagnostic push")
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+ WARNABLE_CODE
+ _Pragma ("GCC diagnostic pop")
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* { dg-options "-Wuninitialized" } */
+
+/* Verify disabling a warning, where both the _Pragma and the
+ affected code are within (different) macros. */
+
+/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning
+ The warning is reported at the macro definition location, rather than
+ the macro expansion location. */
+
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+
+#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */
+
+void test (char yylval)
+{
+ char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ WARNABLE_CODE
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
new file mode 100644
@@ -0,0 +1,21 @@
+/* PR c/69558 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeprecated-declarations" } */
+
+/* Verify disabling -Wdeprecated-declarations, where the _Pragma is in a
+ macro, but the affected code is *not* in a macro. */
+
+#define A \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define B \
+ _Pragma ("GCC diagnostic pop")
+
+__attribute__((deprecated)) void foo (void);
+
+void bar (void)
+{
+ A
+ foo ();
+ B
+}
new file mode 100644
@@ -0,0 +1,16 @@
+/* PR c/69558 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeprecated-declarations" } */
+
+/* Verify disabling -Wdeprecated-declarations, where neither the _Pragma nor
+ the affected code are in macros. */
+
+__attribute__((deprecated)) void foo (void);
+
+void bar (void)
+{
+ _Pragma ("GCC diagnostic push")
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+ foo ();
+ _Pragma ("GCC diagnostic pop")
+}
new file mode 100644
@@ -0,0 +1,19 @@
+/* PR c/69558 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeprecated-declarations" } */
+
+/* Verify disabling -Wdeprecated-declarations, where the _Pragma is not
+ in a macro, but the affected code *is*. */
+
+#define C \
+ foo ();
+
+__attribute__((deprecated)) void foo (void);
+
+void bar (void)
+{
+ _Pragma ("GCC diagnostic push")
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+ C
+ _Pragma ("GCC diagnostic pop")
+}
new file mode 100644
@@ -0,0 +1,23 @@
+/* PR c/69558 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeprecated-declarations" } */
+
+/* Verify disabling -Wdeprecated-declarations, where the _Pragma and the
+ affected code are in different macros. */
+
+#define A \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define B \
+ _Pragma ("GCC diagnostic pop")
+#define C \
+ foo ();
+
+__attribute__((deprecated)) void foo (void);
+
+void bar (void)
+{
+ A
+ C
+ B
+}
new file mode 100644
@@ -0,0 +1,19 @@
+/* PR c/69558 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeprecated-declarations" } */
+
+/* TODO: XFAIL for g++ (works for C). */
+
+#define A \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define B \
+ _Pragma ("GCC diagnostic pop")
+#define C(x) \
+ A \
+ static inline void bar (void) { x (); } /* { dg-bogus "in definition of|deprecated" "" { xfail { c++ } } } */ \
+ B
+
+__attribute__((deprecated)) void foo (void); /* { dg-bogus "declared here" "" { xfail { c++ } } } */
+
+C (foo) /* { dg-bogus "is deprecated" "" { xfail { c++ } } } */
deleted file mode 100644
@@ -1,17 +0,0 @@
-/* PR c/69558 */
-/* { dg-do compile } */
-/* { dg-options "-Wdeprecated-declarations" } */
-
-#define A \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
-#define B \
- _Pragma ("GCC diagnostic pop")
-#define C(x) \
- A \
- static inline void bar (void) { x (); } \
- B
-
-__attribute__((deprecated)) void foo (void); /* { dg-bogus "declared here" } */
-
-C (foo) /* { dg-bogus "is deprecated" } */