public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* A problem of template implicit instantiation
@ 2014-12-05  2:31 Yu Sheng Oh
  2014-12-05 15:19 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Yu Sheng Oh @ 2014-12-05  2:31 UTC (permalink / raw)
  To: gcc-help

HI,

I have a piece of code at http://goo.gl/r2ySE6

Refer to the code, with option of "-O2 -std=c++1y", when we comment
out the statement "id<int>;" clang-3.4.1 compiles the code
successfully, but g++-4.9.0 compiles failed, where g++ complains that
"unresolved overloaded function type", which in turn implies that at
the point of calling compose function, id<int> is not instantiated.

"3. Unless a function template specialization has been explicitly
instantiated or explicitly specialized, *the function template
specialization is implicitly instantiated  when the specialization is
referenced in a context that requires a function definition to exist.*
"[temp.inst]

At the point of calling the compose function, the function definition
for id<int> is required, and so, id<int> should be implicitly
instantiated.

Based on my argument, it is a bug in g++-4.9.0, but I am not 100% sure
of it. Please advice.

PS: Yongwei Wu is credited for discovering the problem.

== off topic==
I think i am going to be pissed off, because of accidentally posting
my question to gcc-bugs mail list. I sincerely apologize for it.
Sorry.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A problem of template implicit instantiation
  2014-12-05  2:31 A problem of template implicit instantiation Yu Sheng Oh
@ 2014-12-05 15:19 ` Jonathan Wakely
  2014-12-05 15:51   ` Yu Sheng Oh
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2014-12-05 15:19 UTC (permalink / raw)
  To: Yu Sheng Oh; +Cc: gcc-help

On 5 December 2014 at 02:31, Yu Sheng Oh wrote:
> HI,
>
> I have a piece of code at http://goo.gl/r2ySE6
>
> Refer to the code, with option of "-O2 -std=c++1y", when we comment
> out the statement "id<int>;" clang-3.4.1 compiles the code
> successfully, but g++-4.9.0 compiles failed, where g++ complains that
> "unresolved overloaded function type", which in turn implies that at
> the point of calling compose function, id<int> is not instantiated.

It does seem to be a bug, but I don't think the problem is that the
function isn't instantiated.

I think the compiler is failing to deduce the return type of id<int>,
because it works if you change it to not use "auto" as the return
type.

I've reported it to Bugzilla as
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59912 with a simpler
example, thanks for reporting it to us.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A problem of template implicit instantiation
  2014-12-05 15:19 ` Jonathan Wakely
@ 2014-12-05 15:51   ` Yu Sheng Oh
  2014-12-05 17:04     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Yu Sheng Oh @ 2014-12-05 15:51 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Yup, it may refer to the same issue which you have pointed out. But,
why the compiler deduce the return type in a inconsistent way, where
it can correctly deduce the return type in a single simple statement,
whereas it fails in another way? Thanks.

On Fri, Dec 5, 2014 at 11:19 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 5 December 2014 at 02:31, Yu Sheng Oh wrote:
>> HI,
>>
>> I have a piece of code at http://goo.gl/r2ySE6
>>
>> Refer to the code, with option of "-O2 -std=c++1y", when we comment
>> out the statement "id<int>;" clang-3.4.1 compiles the code
>> successfully, but g++-4.9.0 compiles failed, where g++ complains that
>> "unresolved overloaded function type", which in turn implies that at
>> the point of calling compose function, id<int> is not instantiated.
>
> It does seem to be a bug, but I don't think the problem is that the
> function isn't instantiated.
>
> I think the compiler is failing to deduce the return type of id<int>,
> because it works if you change it to not use "auto" as the return
> type.
>
> I've reported it to Bugzilla as
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59912 with a simpler
> example, thanks for reporting it to us.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A problem of template implicit instantiation
  2014-12-05 15:51   ` Yu Sheng Oh
@ 2014-12-05 17:04     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2014-12-05 17:04 UTC (permalink / raw)
  To: Yu Sheng Oh; +Cc: gcc-help

On 5 December 2014 at 15:51, Yu Sheng Oh wrote:
> Yup, it may refer to the same issue which you have pointed out.

It's definitely the same issue, I reduced your example to the minimum
necessary to reproduce it and created the bug report.

> But,
> why the compiler deduce the return type in a inconsistent way, where
> it can correctly deduce the return type in a single simple statement,
> whereas it fails in another way? Thanks.

Because there's a bug :-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-05 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-05  2:31 A problem of template implicit instantiation Yu Sheng Oh
2014-12-05 15:19 ` Jonathan Wakely
2014-12-05 15:51   ` Yu Sheng Oh
2014-12-05 17:04     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).