Bug 48500 - Regression: Failing to convert template argument to concrete type, in C++0x mode.
Summary: Regression: Failing to convert template argument to concrete type, in C++0x m...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 major
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-07 17:44 UTC by Jeffrey Yasskin
Modified: 2011-04-08 15:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-07 18:52:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Yasskin 2011-04-07 17:44:13 UTC
This shows up in template functions that try to pass a value whose type is a template argument to a function that expects one or more concrete types. The code compiles in gcc-4.5, produces an error in 4.6.0 and gcc-4_6-branch, and produces an ICE in trunk. All of them succeed in C++98 mode.

$ cat test.cc
struct linked_ptr {
};
template <typename T> linked_ptr make_linked_ptr(T* ptr);
struct Concrete;
struct NewedClass {
  NewedClass(const Concrete& req){}
};
template<typename ArgT> void AddObjToChange(const ArgT& req) {
  linked_ptr p = make_linked_ptr(new NewedClass(req));
}
$ g++-mp-4.5 -c test.cc -std=gnu++0x
$ g++-mp-4.6 -c test.cc -std=gnu++0x # Or gcc-4_6-branch at r172074
test.cc: In function 'void AddObjToChange(const ArgT&)':
test.cc:9:53: error: no matching function for call to 'NewedClass::NewedClass(const ArgT&)'
test.cc:9:53: note: candidates are:
test.cc:6:3: note: NewedClass::NewedClass(const Concrete&)
test.cc:6:3: note:   no known conversion for argument 1 from 'const ArgT' to 'const Concrete&'
test.cc:5:8: note: constexpr NewedClass::NewedClass(const NewedClass&)
test.cc:5:8: note:   no known conversion for argument 1 from 'const ArgT' to 'const NewedClass&'
test.cc:5:8: note: constexpr NewedClass::NewedClass(NewedClass&&)
test.cc:5:8: note:   no known conversion for argument 1 from 'const ArgT' to 'NewedClass&&'
$ trunk-r172073/g++  -std=gnu++0x -c test.cc
test.cc: In function ‘void AddObjToChange(const ArgT&)’:
test.cc:9:53: internal compiler error: tree check: expected record_type or union_type or qual_union_type, have template_type_parm in lookup_base, at cp/search.c:212
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
$

An error in similar code went away with the fix to PR48319.
Comment 1 Jason Merrill 2011-04-08 06:08:37 UTC
Author: jason
Date: Fri Apr  8 06:08:31 2011
New Revision: 172165

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172165
Log:
	PR c++/48500
	* semantics.c (potential_constant_expression_1) [CALL_EXPR]: Check
	arguments even if we don't know the function.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/regress/call1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-04-08 15:02:37 UTC
Author: jason
Date: Fri Apr  8 15:02:28 2011
New Revision: 172195

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172195
Log:
	PR c++/48500
	* semantics.c (potential_constant_expression_1) [CALL_EXPR]: Check
	arguments even if we don't know the function.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/regress/call1.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/semantics.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-04-08 15:16:00 UTC
fixed for 4.6.1.