public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C/C++] PR 13358 long long and C++ do not mix well
@ 2008-08-30  1:11 Manuel López-Ibáñez
  2008-08-30  2:15 ` Joseph S. Myers
  0 siblings, 1 reply; 16+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-30  1:11 UTC (permalink / raw)
  To: Gcc Patch List

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

CPP and the FE were using different semantics. invoke.texi said that
Wlong-long was the default. This was not correct. It was the default
for CPP but -Wno-long-long was the default for the FE. Now there is
only one semantic: the one from the FE.

However, we were inhibiting warning even if the user requested it
through Wlong-long. Now explicit Wlong-long (or Wno-long-long)
overrides everything else, except in system headers.

Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,ada with --target_board=\{-m32,-m64\}

OK for trunk?

2008-08-25  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR 13358
	* doc/invoke.texi (-Wlong-long): Update description.
	* c-opts.c (sanitize_cpp_opts): Synchronize cpp's warn_long_long
	and front-end warn_long_long. Wlong-long only depends on other
	flags if it is uninitialized.
	* c-lex (interpret_integer): Only warn if there was no previous
	overflow and -Wlong-long is enabled.
	* c-decl.c (declspecs_add_type): Drop redundant flags.
	* c.opt (Wlong-long): Init to -1.
	* c-parser.c (disable_extension_diagnostics): warn_long_long is
	the same for CPP and FE.
	(restore_extension_diagnostics): Likewise.
cp/
	* parser.c (cp_parser_check_decl_spec): Drop redundant flags.
testsuite/
	* g++.dg/warn/pr13358.C: New.
	* g++.dg/warn/pr13358-2.C: New.
	* g++.dg/warn/pr13358-3.C: New.	
	* gcc.dg/wtr-int-type-1.c: Use two dg-warning to match two
	messages. Test for "long long" in system headers.

[-- Attachment #2: fix-pr13358-try2.diff --]
[-- Type: text/plain, Size: 10277 bytes --]

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 139674)
+++ gcc/doc/invoke.texi	(working copy)
@@ -4028,14 +4028,13 @@ Warn if a precompiled header (@pxref{Pre
 the search path but can't be used.
 
 @item -Wlong-long
 @opindex Wlong-long
 @opindex Wno-long-long
-Warn if @samp{long long} type is used.  This is default.  To inhibit
-the warning messages, use @option{-Wno-long-long}.  Flags
-@option{-Wlong-long} and @option{-Wno-long-long} are taken into account
-only when @option{-pedantic} flag is used.
+Warn if @samp{long long} type is used.  This is enabled by either
+@option{-pedantic} or @option{-Wtraditional} in ISO C90 and C++98
+modes.  To inhibit the warning messages, use @option{-Wno-long-long}.
 
 @item -Wvariadic-macros
 @opindex Wvariadic-macros
 @opindex Wno-variadic-macros
 Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU
Index: gcc/c-lex.c
===================================================================
--- gcc/c-lex.c	(revision 139674)
+++ gcc/c-lex.c	(working copy)
@@ -580,17 +580,19 @@ interpret_integer (const cpp_token *toke
     /* cpplib has already issued a warning for overflow.  */
     type = ((flags & CPP_N_UNSIGNED)
 	    ? widest_unsigned_literal_type_node
 	    : widest_integer_literal_type_node);
   else
-    type = integer_types[itk];
-
-  if (itk > itk_unsigned_long
-      && (flags & CPP_N_WIDTH) != CPP_N_LARGE
-      && !in_system_header && !flag_isoc99)
-    pedwarn (input_location, 0, "integer constant is too large for %qs type",
-	     (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
+    {
+      type = integer_types[itk];
+      if (itk > itk_unsigned_long
+	  && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
+	pedwarn (input_location, OPT_Wlong_long,
+		 (flags & CPP_N_UNSIGNED) 
+		 ? "integer constant is too large for %<unsigned long%> type"
+		 : "integer constant is too large for %<long%> type");
+    }
 
   value = build_int_cst_wide (type, integer.low, integer.high);
 
   /* Convert imaginary to a complex type.  */
   if (flags & CPP_N_IMAGINARY)
Index: gcc/testsuite/gcc.dg/wtr-int-type-1.c
===================================================================
--- gcc/testsuite/gcc.dg/wtr-int-type-1.c	(revision 139674)
+++ gcc/testsuite/gcc.dg/wtr-int-type-1.c	(working copy)
@@ -23,13 +23,21 @@ testfunc ()
      we can pretend it worked the way it does in C99.]  */
   i = 9223372036854775807;
 
   /* But this one should, since it doesn't fit in long (long), but
      does fit in unsigned long (long).  */
-  i = 18446744073709551615; /* { dg-warning "decimal constant|unsigned" "decimal constant" } */
-  
+  i = 18446744073709551615; /* { dg-warning "integer constant is so large that it is unsigned" "decimal constant" } */
+  /* { dg-warning "this decimal constant would be unsigned in ISO C90" "decimal constant" { target *-*-* } 28 } */
+
 # 29 "sys-header.h" 3
+}
+
+void
+testfunc2( ) 
+{ 
+  long long i;
+
 /* We are in system headers now, no -Wtraditional warnings should issue.  */
 
   i = 0x80000000;
   i = 0xFFFFFFFF;
   i = 037777777777;
@@ -39,5 +47,6 @@ testfunc ()
   i = 01777777777777777777777;
   
   i = 9223372036854775807;
   i = 18446744073709551615;
 }
+
Index: gcc/testsuite/g++.dg/warn/pr13358-2.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr13358-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr13358-2.C	(revision 0)
@@ -0,0 +1,15 @@
+// PR c++/13358: g++ should accept a long long constant sans LL suffix
+// if -Wno-long-long is in use
+// { dg-do compile }
+// { dg-require-effective-target ilp32 }
+// { dg-options "-std=c++98 -pedantic-errors" }
+
+
+void use_longlong ()
+{
+  unsigned long long x1, x2, x3; // { dg-error "error: ISO C\\+\\+ 1998 does not support 'long long'" }
+  // make sure we error with hex, decimal and octal
+  x1 = 0x1b27da572ef3cd86; // { dg-error "error: integer constant is too large for 'long' type" }
+  x2 = 1956772631100509574; // { dg-error "error: integer constant is too large for 'long' type" }
+  x3 = 0154476645345674746606; // { dg-error "error: integer constant is too large for 'long' type" }
+}
Index: gcc/testsuite/g++.dg/warn/pr13358-3.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr13358-3.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr13358-3.C	(revision 0)
@@ -0,0 +1,15 @@
+// PR c++/13358: g++ should accept a long long constant sans LL suffix
+// if -Wno-long-long is in use
+// { dg-do compile }
+// { dg-require-effective-target int32plus } 
+// { dg-options "-std=c++0x -pedantic-errors" }
+
+
+void use_longlong ()
+{
+  unsigned long long x1, x2, x3; 
+  // make sure it's ok with hex, decimal and octal
+  x1 = 0x1b27da572ef3cd86;
+  x2 = 1956772631100509574;
+  x3 = 0154476645345674746606;
+}
Index: gcc/testsuite/g++.dg/warn/pr13358.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr13358.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr13358.C	(revision 0)
@@ -0,0 +1,15 @@
+// PR c++/13358: g++ should accept a long long constant sans LL suffix
+// if -Wno-long-long is in use
+// { dg-do compile }
+// { dg-require-effective-target int32plus } 
+// { dg-options "-std=c++98 -Wno-long-long -pedantic-errors" }
+
+
+void use_longlong ()
+{
+  unsigned long long x1, x2, x3; 
+  // make sure it's ok with hex, decimal and octal
+  x1 = 0x1b27da572ef3cd86;
+  x2 = 1956772631100509574;
+  x3 = 0154476645345674746606;
+}
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 139674)
+++ gcc/cp/parser.c	(working copy)
@@ -2158,12 +2158,11 @@ cp_parser_check_decl_spec (cp_decl_speci
       /* The "long" specifier is a special case because of "long long".  */
       if (ds == ds_long)
 	{
 	  if (count > 2)
 	    error ("%H%<long long long%> is too long for GCC", &location);
-	  else if (pedantic && !in_system_header && warn_long_long
-                   && cxx_dialect == cxx98)
+	  else 
 	    pedwarn (location, OPT_Wlong_long, 
 		     "ISO C++ 1998 does not support %<long long%>");
 	}
       else if (count > 1)
 	{
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 139674)
+++ gcc/c-decl.c	(working copy)
@@ -7189,12 +7189,11 @@ declspecs_add_type (struct c_declspecs *
 		    {
 		      error ("both %<long long%> and %<double%> in "
 			     "declaration specifiers");
 		      break;
 		    }
-		  if (pedantic && !flag_isoc99 && !in_system_header)
-		    pedwarn (input_location, OPT_Wlong_long, "ISO C90 does not support %<long long%>");
+		  pedwarn (input_location, OPT_Wlong_long, "ISO C90 does not support %<long long%>");
 		  specs->long_long_p = 1;
 		  break;
 		}
 	      if (specs->short_p)
 		error ("both %<long%> and %<short%> in "
Index: gcc/c.opt
===================================================================
--- gcc/c.opt	(revision 139674)
+++ gcc/c.opt	(working copy)
@@ -275,11 +275,11 @@ Warn about invalid uses of the \"offseto
 Winvalid-pch
 C ObjC C++ ObjC++ Warning
 Warn about PCH files that are found but not used
 
 Wlong-long
-C ObjC C++ ObjC++ Var(warn_long_long) Init(1) Warning
+C ObjC C++ ObjC++ Var(warn_long_long) Init(-1) Warning
 Do not warn about using \"long long\" when -pedantic
 
 Wmain
 C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning
 Warn about suspicious declarations of \"main\"
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c	(revision 139674)
+++ gcc/c-opts.c	(working copy)
@@ -1390,18 +1390,19 @@ sanitize_cpp_opts (void)
     error ("-MG may only be used with -M or -MM");
 
   cpp_opts->unsigned_char = !flag_signed_char;
   cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
 
-  /* We want -Wno-long-long to override -pedantic -std=non-c99
-     and/or -Wtraditional, whatever the ordering.  */
-  cpp_opts->warn_long_long
-    = warn_long_long && ((pedantic
-			  && (c_dialect_cxx ()
-			      ? cxx_dialect == cxx98
-			      : !flag_isoc99))
-                         || warn_traditional);
+  /* Wlong-long is disabled by default. It is enabled by:
+      [-pedantic | -Wtraditional] -std=[gnu|c]++98 ; or
+      [-pedantic | -Wtraditional] -std=non-c99 . 
+
+      Either -Wlong-long or -Wno-long-long override any other settings.  */
+  if (warn_long_long == -1)
+    warn_long_long = ((pedantic || warn_traditional)
+		      && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
+  cpp_opts->warn_long_long = warn_long_long;
 
   /* Similarly with -Wno-variadic-macros.  No check for c99 here, since
      this also turns off warnings about GCCs extension.  */
   cpp_opts->warn_variadic_macros
     = warn_variadic_macros && (pedantic || warn_traditional);
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c	(revision 139674)
+++ gcc/c-parser.c	(working copy)
@@ -815,18 +815,16 @@ disable_extension_diagnostics (void)
 {
   int ret = (pedantic
 	     | (warn_pointer_arith << 1)
 	     | (warn_traditional << 2)
 	     | (flag_iso << 3)
-	     | (warn_long_long << 4)
-	     | (cpp_opts->warn_long_long << 5));
+	     | (warn_long_long << 4));
   cpp_opts->pedantic = pedantic = 0;
   warn_pointer_arith = 0;
   cpp_opts->warn_traditional = warn_traditional = 0;
   flag_iso = 0;
-  warn_long_long = 0;
-  cpp_opts->warn_long_long = 0;
+  cpp_opts->warn_long_long = warn_long_long = 0;
   return ret;
 }
 
 /* Restore the warning flags which are controlled by __extension__.
    FLAGS is the return value from disable_extension_diagnostics.  */
@@ -836,12 +834,11 @@ restore_extension_diagnostics (int flags
 {
   cpp_opts->pedantic = pedantic = flags & 1;
   warn_pointer_arith = (flags >> 1) & 1;
   cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
   flag_iso = (flags >> 3) & 1;
-  warn_long_long = (flags >> 4) & 1;
-  cpp_opts->warn_long_long = (flags >> 5) & 1;
+  cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
 }
 
 /* Possibly kinds of declarator to parse.  */
 typedef enum c_dtr_syn {
   /* A normal declarator with an identifier.  */

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-04-24 13:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-30  1:11 [C/C++] PR 13358 long long and C++ do not mix well Manuel López-Ibáñez
2008-08-30  2:15 ` Joseph S. Myers
2008-08-30  9:52   ` Manuel López-Ibáñez
2008-10-23  2:42     ` Manuel López-Ibáñez
2009-04-10 19:12       ` Manuel López-Ibáñez
2009-04-10 21:41         ` Joseph S. Myers
2009-04-19 11:16           ` Manuel López-Ibáñez
2009-04-20  3:34             ` Mark Mitchell
2009-04-20  8:38               ` Manuel López-Ibáñez
2009-04-20 15:14                 ` Mark Mitchell
2009-04-20 16:17                   ` Manuel López-Ibáñez
2009-04-20 16:26                     ` Mark Mitchell
2009-04-20 17:38                       ` Jason Merrill
2009-04-23  9:15                         ` Dave Korn
2009-04-23 23:46                           ` Mark Mitchell
2009-04-24 13:39                             ` Dave Korn

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).