Bug 53624 - GCC rejects function local types in template function with default template arguments
Summary: GCC rejects function local types in template function with default template a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.3
: P3 normal
Target Milestone: 4.8.0
Assignee: Paolo Carlini
URL:
Keywords:
: 54104 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-10 03:38 UTC by Daniel Lunow
Modified: 2012-07-31 09:49 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-07-28 00:00:00


Attachments
testcase (76 bytes, text/plain)
2012-06-10 03:38 UTC, Daniel Lunow
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Lunow 2012-06-10 03:38:16 UTC
Created attachment 27595 [details]
testcase

The error occurs when there is at one template argument with default and one without. Errors are generated for local structs, classes, unions and lambda functions.
For the attached usecase I get with gcc 4.6.3 and 4.7.0:
C:\dev\projects\compiler test>g++ gcc_test2.cpp --std=c++0x -fsyntax-only
gcc_test2.cpp: In function 'void Foo(T)':
gcc_test2.cpp:5:12: error: no default argument for 'T'
Comment 1 Andrew Pinski 2012-06-10 04:24:44 UTC
>gcc_test2.cpp:5:12: error: no default argument for 'T'

It is not rejecting the local type but rather it is rejecting the second template argument which does not have a default argument even though the first argument does.
Comment 2 Daniel Lunow 2012-06-10 04:49:29 UTC
Their is no requirement (in the c++11 standard) for function templates that implies subsequent template parameters after a template parameter with default template argument must also have default template arguments (in contrast to class templates). In general this works in gcc.
But with the local types inside the template function gcc might reject it because it creates local types as templated with the same template parameters/default arguments and checks the requirement for class templates.

The line number/offset in the error message clearly refers to the local struct.
Comment 3 Andrew Pinski 2012-06-10 04:52:21 UTC
Oh I see.
The trunk shows what is going on better:
t.cc: In function ‘void Foo(T)’:
t.cc:4:12: error: no default argument for ‘T’
   struct X {};
            ^
Comment 4 Paolo Carlini 2012-07-28 13:17:35 UTC
*** Bug 54104 has been marked as a duplicate of this bug. ***
Comment 5 Paolo Carlini 2012-07-28 13:20:08 UTC
Looking into it.
Comment 6 paolo@gcc.gnu.org 2012-07-31 09:46:59 UTC
Author: paolo
Date: Tue Jul 31 09:46:46 2012
New Revision: 190001

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190001
Log:
/cp
2012-07-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53624
	* pt.c (check_default_tmpl_args): Don't check local types.

/testsuite
2012-07-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53624
	* g++.dg/cpp0x/temp_default5.C: New.


Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/temp_default5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Paolo Carlini 2012-07-31 09:49:41 UTC
Fixed.