This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c++/6634: Diagnose "long lond double"


Currently the C++ frontend fails to diagnose the invalid data type
"long long double" without "-pedantic" and generates a
long_double_type_node for it, but treats it later as "long long int".

The following patch adds a check in grokdeclarator so we don't generate
a long_double_type_node for it.

When I wanted to add the second check for the additional diagnostic,
I noticed that the current diagnostic machinery was broken. For example:

      if (TREE_CODE (type) == REAL_TYPE)
	error ("short, signed or unsigned invalid for %qs", name);
      ....
      else if ((long_p|| short_p) && TREE_CODE (type) == REAL_TYPE)
	error ("long or short specified with floating type for %qs", name);

Consequently, the second error message was never issued.
This resulted in a bogus message for the following testcase:

  long float z;

  bug:cc: error: short, signed or unsigned invalid for 'z'

Note, that "long" isn't mentioned in the message.

The patch cleans up the diagnostic machinery, by first checking
signedness and then length modifiers, adding checks for "long long".
The error messages now don't try to mention all combinations of
invalid modifiers, but only complain about the first one that is
actually wrong.

Btw, should I add quotes to the modifiers in the error messages like

  error ("%<signed%> and %<unsigned%> given together for %qs", name);


Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

Regards,
Volker

:ADDPATCH C++:


2006-03-06  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/6634
	decl.c (grokdeclarator): Do not accept long long double.
	Reorganize checks for invalid (combinations of) type modifiers.

=====================================================================
*** gcc/gcc/cp/decl.c	Sun Mar  5 14:32:35 2006
--- gcc/gcc/cp/decl.c	Sun Mar  5 15:16:15 2006
*************** grokdeclarator (const cp_declarator *dec
*** 6954,6960 ****
       and check for invalid combinations.  */
  
    /* Long double is a special combination.  */
!   if (long_p && TYPE_MAIN_VARIANT (type) == double_type_node)
      {
        long_p = false;
        type = build_qualified_type (long_double_type_node,
--- 6954,6960 ----
       and check for invalid combinations.  */
  
    /* Long double is a special combination.  */
!   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
      {
        long_p = false;
        type = build_qualified_type (long_double_type_node,
*************** grokdeclarator (const cp_declarator *dec
*** 6967,6984 ****
      {
        int ok = 0;
  
!       if (TREE_CODE (type) == REAL_TYPE)
! 	error ("short, signed or unsigned invalid for %qs", name);
!       else if (TREE_CODE (type) != INTEGER_TYPE)
! 	error ("long, short, signed or unsigned invalid for %qs", name);
!       else if (long_p && short_p)
! 	error ("long and short specified together for %qs", name);
        else if ((long_p || short_p) && explicit_char)
  	error ("long or short specified with char for %qs", name);
!       else if ((long_p|| short_p) && TREE_CODE (type) == REAL_TYPE)
! 	error ("long or short specified with floating type for %qs", name);
!       else if (signed_p && unsigned_p)
! 	error ("signed and unsigned given together for %qs", name);
        else
  	{
  	  ok = 1;
--- 6967,6986 ----
      {
        int ok = 0;
  
!       if ((signed_p || unsigned_p) && TREE_CODE (type) != INTEGER_TYPE)
! 	error ("signed or unsigned invalid for %qs", name);
!       else if (signed_p && unsigned_p)
! 	error ("signed and unsigned specified together for %qs", name);
!       else if (longlong && TREE_CODE (type) != INTEGER_TYPE)
! 	error ("long long invalid for %qs", name);
!       else if (long_p && TREE_CODE (type) == REAL_TYPE)
! 	error ("long invalid for %qs", name);
!       else if (short_p && TREE_CODE (type) == REAL_TYPE)
! 	error ("short invalid for %qs", name);
        else if ((long_p || short_p) && explicit_char)
  	error ("long or short specified with char for %qs", name);
!       else if (long_p && short_p)
! 	error ("long and short specified together for %qs", name);
        else
  	{
  	  ok = 1;
=====================================================================

2006-03-06  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/6634
	g++.dg/parse/long1.C: New test.

=====================================================================
--- gcc/gcc/testsuite/g++.dg/parse/long1.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/parse/long1.C	2006-03-06 18:13:04 +0100
@@ -0,0 +1,9 @@
+// PR c++/6634
+// { dg-do compile }
+// { dg-options "" }
+
+long long double x; // { dg-error "long long" }
+long double y;
+long float z;       // { dg-error "long" }
=====================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]