public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52422] New: [C++11][SFINAE] Hard errors with void or arithmetic expressions
@ 2012-02-28 20:10 daniel.kruegler at googlemail dot com
  2012-02-28 20:43 ` [Bug c++/52422] " paolo.carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-02-28 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52422
           Summary: [C++11][SFINAE] Hard errors with void or arithmetic
                    expressions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com


gcc 4.7.0 20120225 (experimental) in C++11 mode produces a hard compiler error
during a sfinae-conforming situation involving function-like or pointer-like
expressions:

//---
template<class T>
struct add_rval_ref
{
  typedef T&& type;
};

template<>
struct add_rval_ref<void>
{
  typedef void type;
};

template<class T>
typename add_rval_ref<T>::type create();

template<class T, 
  class = decltype(create<T>()()) // line 17
>
auto f(int) -> char(&)[1];

template<class>
auto f(...) -> char(&)[2];

static_assert(sizeof(f<void>(0)) != 1, "");
//---

"16|error: void value not ignored as it ought to be"

Here some further variations of the theme:

a) Replace line 17 by

class = decltype(*create<T>()) // line 17

b) Replace above test by

//---
template<class T>
struct add_rval_ref
{
  typedef T&& type;
};

template<>
struct add_rval_ref<void>
{
  typedef void type;
};

template<class T>
typename add_rval_ref<T>::type create();

template<class T, class U,
  class = decltype( (create<T>().*create<U>())() ) // line 17
>
auto f(int) -> char(&)[1];

template<class, class>
auto f(...) -> char(&)[2];

static_assert(sizeof(f<void, void>(0)) != 1, ""); // line 24
//---

"17|error: 'create<void>()' cannot be used as a member pointer, since it is of
type 'add_rval_ref<void>::type {aka void}'"

c) Replace in the test (b) line 24 by the following line:

static_assert(sizeof(f<int, int>(0)) != 1, ""); // line 24

"17|error: 'create<int>()' cannot be used as a member pointer, since it is of
type 'int'"

d) Replace line 17 in the test (b) by the following line and use either of
"void, void" or "int, int" as template arguments in line 24:

class = decltype( create<T>().*create<U>() )

"17|error: 'create<void>()' cannot be used as a member pointer, since it is of
type 'add_rval_ref<void>::type {aka void}'"

or

"17|error: 'create<int>()' cannot be used as a member pointer, since it is of
type 'int'"

respectively.


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

end of thread, other threads:[~2012-04-18 10:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28 20:10 [Bug c++/52422] New: [C++11][SFINAE] Hard errors with void or arithmetic expressions daniel.kruegler at googlemail dot com
2012-02-28 20:43 ` [Bug c++/52422] " paolo.carlini at oracle dot com
2012-02-28 23:41 ` paolo.carlini at oracle dot com
2012-04-18 10:27 ` paolo at gcc dot gnu.org
2012-04-18 10:32 ` paolo.carlini at oracle dot com

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