Bug 32385 - g++ rejects struct in default argument of template function
Summary: g++ rejects struct in default argument of template function
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-06-17 23:24 UTC by Volker Reichelt
Modified: 2021-07-24 05:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-03-31 20:11:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2007-06-17 23:24:35 UTC
The following code snippet triggers a segfault since GCC 4.0.0:

=================================================================
struct A
{
  template<int> void foo(int = ((struct { int i; }) {0}).i);
};
=================================================================

bug.cc:3: error: template class without a name
bug.cc:3: error: 'struct A::<anonymous>' does not declare a template type
bug.cc:3: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]
Comment 1 Paolo Carlini 2007-09-25 17:39:55 UTC
Note: given the C99 extensions, this is actually reject-valid: for instance Comeau in relaxed mode accepts it.
Comment 2 Joseph S. Myers 2008-07-04 22:14:02 UTC
Closing 4.1 branch.
Comment 3 Volker Reichelt 2008-09-30 21:44:25 UTC
With the patch for PR37649 the testcase doesn't ICE on mainline anymore.
According to Paolo's comment, this is still rejects-valid, though.
Comment 4 Joseph S. Myers 2009-03-31 20:11:12 UTC
Closing 4.2 branch.
Comment 5 Richard Biener 2009-08-04 12:28:16 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 6 Richard Biener 2010-05-22 18:11:38 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 7 Jason Merrill 2011-03-13 01:21:41 UTC
Only the ICE was a regression; that's fixed, so this is no longer a regression bug.
Comment 8 Andrew Pinski 2021-07-24 01:55:54 UTC
clang also rejects this:
<source>:3:34: error: 'A::(unnamed struct at <source>:3:34)' cannot be defined in a type specifier
  template<int> void foo(int = ((struct { int i; }) {0}).i);
                                 ^
<source>:3:57: error: member reference base type 'void' is not a structure or union
  template<int> void foo(int = ((struct { int i; }) {0}).i);
                               ~~~~~~~~~~~~~~~~~~~~~~~~~^~
2 errors generated.