public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: sebor@roguewave.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/10690: bogus ambiguity on templates overloaded on return type
Date: Thu, 08 May 2003 18:46:00 -0000	[thread overview]
Message-ID: <20030508183848.26535.qmail@sources.redhat.com> (raw)


>Number:         10690
>Category:       c++
>Synopsis:       bogus ambiguity on templates overloaded on return type
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 08 18:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     sebor@roguewave.com
>Release:        3.2.2
>Organization:
>Environment:

>Description:
The attached well-formed program inspired by the CUJ 6/03 article "Function Overloading Based on Arbitrary
Properties of Types," fails to compile with gcc 3.2.2.

The errors after replacing the dependency on <typeinfo>
with __PRETTY_FUNCTION__ are:

t.cpp:24: new declaration `template<class T> select<(!is_int<T>::value), 
   T>::type foo(T)'
t.cpp:17: ambiguates old declaration `template<class T> 
   select<is_int<T>::value, T>::type foo(T)'

Regards
Martin
>How-To-Repeat:
$ cat t.cpp && g++ --version && g++ t.cpp
#include  <typeinfo>

template <bool B, class T>
struct select { typedef T type; };

template <class T>
struct select<false, T> { };

template <class T>
struct is_int { enum { value }; };

template <>
struct is_int<int> { enum { value = 1 }; };

extern "C" int printf (const char*, ...);

template <class T>
typename select<is_int<T>::value, T>::type
foo (T t) {
     printf ("%s:%d: %s\n", __FILE__, __LINE__, typeid (foo<T>).name ());
     return t;
}

template <class T>
typename select<!is_int<T>::value, T>::type
foo (T t) {
    printf ("%s:%d: %s\n", __FILE__, __LINE__, typeid (foo<T>).name ());
    return t;
}

int main ()
{
     foo (bool ());
     foo (short ());
     foo (int ());
}
g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

t.cpp:26: new declaration `template<class T> select<(!is_int<T>::value), 
   T>::type foo(T)'
t.cpp:19: ambiguates old declaration `template<class T> 
   select<is_int<T>::value, T>::type foo(T)'
t.cpp: In function `select<(!is_int<T>::value), T>::type foo(T) [with T = 
   bool]':
t.cpp:33:   instantiated from here
t.cpp:27: insufficient contextual information to determine type
t.cpp: In function `select<(!is_int<T>::value), T>::type foo(T) [with T = short 
   int]':
t.cpp:34:   instantiated from here
t.cpp:27: insufficient contextual information to determine type
t.cpp: In function `select<is_int<T>::value, T>::type foo(T) [with T = int]':
t.cpp:35:   instantiated from here
t.cpp:20: insufficient contextual information to determine type
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-05-08 18:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-08 18:46 sebor [this message]
2003-05-08 19:56 giovannibajo
2003-05-08 20:56 Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030508183848.26535.qmail@sources.redhat.com \
    --to=sebor@roguewave.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).