Bug 15317 - [3.4/4.0 Regression] __attribute__ unused in first parameter of constructor gives error
Bug#: 15317 Product:  gcc Version: 3.4.0
Host: sparc-sun-solaris2.8 Target: sparc-sun-solaris2.8 Build: sparc-sun-solaris2.8
Status: RESOLVED Severity: minor Priority: P1
Resolution: FIXED Assigned To: mark@codesourcery.com Reported By: mb@apissoft.com
Component: c++ Target Milestone: 3.4.1
Summary: [3.4/4.0 Regression] __attribute__ unused in first parameter of constructor gives error
Keywords:  rejects-valid
Opened: 2004-05-06 14:14
Description:   Last confirmed: 2004-05-06 14:43 Opened: 2004-05-06 14:14
If the first parameter of a constructor is marked as unused i always get the
error:
x25.cpp:26: error: expected unqualified-id before "const"
x25.cpp:26: error: expected `)' before "const"
x25.cpp:26: error: expected `,' or `;' before "const
where the line is
x25.cpp:26: CommonX25::CommonX25(UNUSED const char *lName, UNUSED const char
*rName, UNUSED const char *source, UNUSED const char *dest)

Michael

------- Comment #1 From Wolfgang Bangerth 2004-05-06 14:29 -------
Can you give us a small testcase? 
Thanks 
  Wolfgang 

------- Comment #2 From Andrew Pinski 2004-05-06 14:33 -------
With a simple testcase I cannot verify it:
struct A
{
void f(const int *, const int *);
};

void A::f(__attribute__((unused)) const int *i, __attribute__((unused)) const int *i2)
{
}

Are sure that UNUSED is defined to be the attribute?

------- Comment #3 From mb@apissoft.com 2004-05-06 14:36 -------
small testcase:

class CommonX25 {
 private:
#if defined AIX && !defined AIX43
 ...
#endif /* AIX */

 public:
  CommonX25(const char *, const char *, const char *, const char *);
  ~CommonX25();
};

CommonX25::CommonX25(__attribute__ ((unused)) const char *lName, __attribute__ (
(unused)) const char *rName, __attribute__ ((unused)) const char *source, __attr
ibute__ ((unused)) const char *dest)
{
#if defined AIX && !defined AIX43
  ...
#else
  cerr << "CommonX25 not implemented" << endl;
  exit(-1);
#endif
}

compiled with:
 g++ -c -o test.o test.cpp

------- Comment #4 From Andrew Pinski 2004-05-06 14:43 -------
Confirmed, reduced example:
struct A
{
  A(char);
};
A::A(__attribute__((unused)) char i2)
{}

------- Comment #5 From Andrew Pinski 2004-05-06 14:44 -------
A work around is to place the attribute after the variable name but this works
only on 3.4.0 and above:
struct A
{
A(char);
};
A::A(char i2 __attribute__((unused)))
{}

------- Comment #6 From CVS Commits 2004-05-24 02:23 -------
Subject: Bug 15317

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:22:19

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog parser.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/ext: attrib14.C 
	gcc/testsuite/g++.dg/template: error12.C ptrmem9.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib14.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.182&r2=1.3389.2.183
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.105&r2=1.3892.2.106
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.27&r2=1.157.2.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.15&r2=1.519.2.16
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib14.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.2.16.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error12.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem9.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1


------- Comment #7 From CVS Commits 2004-05-24 02:29 -------
Subject: Bug 15317

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:29:35

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog parser.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/ext: attrib15.C 
	gcc/testsuite/g++.dg/template: error12.C ptrmem9.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib15.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3777&r2=1.3778
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4056&r2=1.4057
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.194&r2=1.195
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.543&r2=1.544
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib15.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error12.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem9.C.diff?cvsroot=gcc&r1=1.1&r2=1.2


------- Comment #8 From CVS Commits 2004-05-24 02:30 -------
Subject: Bug 15317

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:30:28

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: attrib15.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib15.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.183&r2=1.3389.2.184
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib15.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1


------- Comment #9 From Mark Mitchell 2004-05-24 02:34 -------
Fixed in GCC 3.4.1.