Bug 50370 - [C++0x] Multiple declarations with default template arguments accepted
Summary: [C++0x] Multiple declarations with default template arguments accepted
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 82850 87234 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-09-12 21:35 UTC by Daniel Krügler
Modified: 2020-07-16 17:29 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-07-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-09-12 21:35:30 UTC
gcc 4.7.0 20110903 (experimental) in C++0x mode accepts the following code:

template<class T, class = int>
void foo(T);

template<class T, class = int>
void foo(T) {}

template<class = int>
void bar();

template<class = int>
void bar() {}

int main() {
  foo(12);
  bar();
}

According to 14.1 [temp.param] p12 this code should be rejected:

"A template-parameter shall not be given default arguments by two different declarations in the same scope. [ Example:
  template<class T = int> class X;
  template<class T = int> class X { /*... */ }; // error
—end example ]"

gcc correctly rejects such examples when class templates are involved, but fails to do so for function templates. 

This looks very similar to bug 15339 or bug 48372, but the domain (default template arguments) is different.
Comment 1 Andrew Pinski 2012-01-28 05:51:53 UTC
Confirmed.
Comment 2 Johnny Willemsen 2013-09-16 14:34:50 UTC
Also reproduced with GCC 4.8.1
Comment 3 Marek Polacek 2020-07-16 17:07:55 UTC
*** Bug 82850 has been marked as a duplicate of this bug. ***
Comment 4 Marek Polacek 2020-07-16 17:29:09 UTC
*** Bug 87234 has been marked as a duplicate of this bug. ***