public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/34877]  New: Invalid conversion in lookup of variadic template
@ 2008-01-20  1:48 rbuergel at web dot de
  2008-01-20  1:50 ` [Bug c++/34877] " pinskia at gcc dot gnu dot org
  2008-01-20  2:57 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: rbuergel at web dot de @ 2008-01-20  1:48 UTC (permalink / raw)
  To: gcc-bugs

consider template<typename T, typename... Args> T max( T a, T b, Args... args
);

template<typename T> T max( T a)
{
    return a;
}

template<typename T, typename... Args> T max( T a, T b, Args... args )
{
    return a > max<T>(b, args...) ? a : max<T>(b, args...);
}

#include <iostream>
int main()
{
        std::cout << max(3u, 2u, -1) << std::endl;
}

Guess, what it prints: 4294967295

That means, the -1 is converted from signed int to unsigned int in the call to
max(2u, -1) [ with T = unsigned int, Args = ], which may not occur in a
template lookup! The call should be rejected as invalid by the compiler,
because it must not find a definition for max(unsigned int, int).

This happens only in the recursion of the variadic template, calling max(3u,
-1) is rejected as desired.

gcc version 4.3.0-20080111


-- 
           Summary: Invalid conversion in lookup of variadic template
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rbuergel at web dot de


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


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

* [Bug c++/34877] Invalid conversion in lookup of variadic template
  2008-01-20  1:48 [Bug c++/34877] New: Invalid conversion in lookup of variadic template rbuergel at web dot de
@ 2008-01-20  1:50 ` pinskia at gcc dot gnu dot org
  2008-01-20  2:57 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-01-20  1:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-01-20 01:46 -------
I think this is valid code as you specify max<T>(b, args...) which means the
type for the first template argument will be unsigned so it will convert the
second argument to unsigned int.

Isn't that correct?


-- 


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


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

* [Bug c++/34877] Invalid conversion in lookup of variadic template
  2008-01-20  1:48 [Bug c++/34877] New: Invalid conversion in lookup of variadic template rbuergel at web dot de
  2008-01-20  1:50 ` [Bug c++/34877] " pinskia at gcc dot gnu dot org
@ 2008-01-20  2:57 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-01-20  2:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-01-20 01:49 -------
This is accepted for the same reason why the code you have is accepted:
       std::cout << max<unsigned>(3u, -1) << std::endl;


If we write the second max as:
template<typename T, typename... Args> T max( T a, T b, Args... args )
{
   return a > max(b, args...) ? a : max(b, args...);
}

We get a correct rejection so this is not a bug.

t.cc: In function 'T max(T, T, Args ...) [with T = unsigned int, Args = int]':
t.cc:17:   instantiated from here
t.cc:11: error: no matching function for call to 'max(unsigned int&, int&)'
t.cc:11: error: no matching function for call to 'max(unsigned int&, int&)'


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2008-01-20  1:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-20  1:48 [Bug c++/34877] New: Invalid conversion in lookup of variadic template rbuergel at web dot de
2008-01-20  1:50 ` [Bug c++/34877] " pinskia at gcc dot gnu dot org
2008-01-20  2:57 ` pinskia at gcc dot gnu dot org

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).