]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* typeck.c (cp_build_unary_op): Only complain about taking address
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Feb 2009 23:09:11 +0000 (23:09 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Feb 2009 23:09:11 +0000 (23:09 +0000)
        of main if pedantic.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143911 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/main-4.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.bugs/900227_01.C

index 9d425ab1dfa06daefffa0dd23ced00a5ac199db8..c2765daac81665a58649a8c84b59b5f63813aa91 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-03  Jason Merrill  <jason@redhat.com>
+
+       * typeck.c (cp_build_unary_op): Only complain about taking address
+       of main if pedantic.
+
 2009-02-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR inline-asm/39059
index 1c7df31c9bb2d29d0f6ebb67db640ab2c527f946..c58d40b9195563de39dfb19734b02532137ecb97 100644 (file)
@@ -4473,12 +4473,15 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
          arg = build1 (CONVERT_EXPR, type, arg);
          return arg;
        }
-      else if (DECL_MAIN_P (arg))
+      else if (pedantic && DECL_MAIN_P (arg))
         {
           /* ARM $3.4 */
-          if (complain & tf_error)
-            permerror (input_location, "ISO C++ forbids taking address of function %<::main%>");
-          else
+         /* Apparently a lot of autoconf scripts for C++ packages do this,
+            so only complain if -pedantic.  */
+          if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
+            pedwarn (input_location, OPT_pedantic,
+                    "ISO C++ forbids taking address of function %<::main%>");
+          else if (flag_pedantic_errors)
             return error_mark_node;
         }
 
index 9d50d7fc9893fd0c6f6c843d6025df8e2bf852c7..67369d996cd04b0f85adb04f20cbb39fe8e98cba 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-03  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/warn/main-4.C: New test.
+       * g++.old-deja/g++.bugs/900227_01.C: Remove &main warnings.
+
 2009-02-03  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR C++/36607
diff --git a/gcc/testsuite/g++.dg/warn/main-4.C b/gcc/testsuite/g++.dg/warn/main-4.C
new file mode 100644 (file)
index 0000000..ad2dd70
--- /dev/null
@@ -0,0 +1,5 @@
+// This pattern is used by a lot of autoconf scripts, so don't
+// complain about it unless -pedantic.
+// { dg-options "" }
+
+int main () { main (); return 0; }
index 2bd4f3d76c25028d248492579530472d9879e834..b441eff650acd73851dc5d02375a698417d13ab2 100644 (file)
@@ -33,9 +33,7 @@
 
 int main ();
 
-short s = (short) &main;       // { dg-error "taking address" "addr" { xfail h8*-*-* xstormy16-*-* } }
-// { dg-error "loses precision" "lose" { xfail h8*-*-* xstormy16-*-* } 36 }
-char c = (char) &main;         // { dg-error "taking address" }
-// { dg-error "loses precision" "lose" { target *-*-* } 38 }
+short s = (short) &main;       // { dg-error "loses precision" "lose" { xfail h8*-*-* xstormy16-*-* } }
+char c = (char) &main;         // { dg-error "loses precision" "lose" }
 
 int main () { return 0; }