[Bug c++/50370] New: [C++0x] Multiple declarations with default template arguments accepted

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Mon Sep 12 22:34:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50370

             Bug #: 50370
           Summary: [C++0x] Multiple declarations with default template
                    arguments accepted
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com
                CC: jason@redhat.com


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.



More information about the Gcc-bugs mailing list