public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well
@ 2011-04-05 18:45 gintensubaru at gmail dot com
  2011-04-06 13:37 ` [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not " jason at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gintensubaru at gmail dot com @ 2011-04-05 18:45 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [C++0x][SFINAE] noexcept operator does handle function
                    templates well
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gintensubaru@gmail.com


template<class T>
T&& declval() noexcept;

template< class T >
inline void f1( T& x ) noexcept( noexcept( declval<T&>().foo() ) )
{
  x.foo();
}

template< class T,
  bool Noexcept = noexcept( declval<T&>().foo() )
>
inline void f2( T& x ) noexcept( Noexcept )
{
  x.foo();
}

// a common and trivial mistake
template< class T >
inline void f3( T& x ) noexcept( declval<T&>().foo() )
{
  x.foo();
}


struct X
{
  void foo();
};

struct Y
{
  void foo() noexcept;
};

struct Z {};


int main()
{
  X x; Y y; Z z;

  static_assert( !noexcept( f1(x) ), "OK." );
  static_assert( !noexcept( f2(x) ), "OK." );
  // static_assert( !noexcept( f3(x) ), "shall be ill-formed(OK)." );

  static_assert(  noexcept( f1(y) ), "OK." );
  static_assert(  noexcept( f2(y) ), "OK." );
  // static_assert(  noexcept( f3(y) ), "shall be ill-formed(OK)." );

  static_assert(  noexcept( f1(z) ), "shall be ill-formed." );
  static_assert(  noexcept( f2(z) ), "shall be ill-formed." );
  static_assert( !noexcept( f3(z) ), "shall be ill-formed." );

}

---------------------

GCC-4.6.0 compiles this code successfully, but expressions "noexcept( f1(z) )",
"noexcept( f2(z) )", and "noexcept( f3(z) )" shall be ill-formed, because
unevaluated operand "declval<T&>().foo()" is ill-formed.


This behavior prevents using noexcept for switching implementations by SFINAE:

---------------------

// if x.swap(y) is exist, calls it.
template<class T>
void my_swap_( T& x, T& y, int )
  noexcept( noexcept( std::declval<T&>().swap( std::declval<T&>() ) ) )
{
  x.swap( y );
}

// otherwise, calls [std::]swap
using std::swap;
template<class T>
void my_swap_( T& x, T& y, ... )
  noexcept( noexcept( swap( std::declval<T&>(), std::declval<T&>() ) ) )
{
  swap( x, y );
}


template<class T>
void my_swap( T& x, T& y )
  noexcept( noexcept( my_swap_( std::declval<T&>(), std::declval<T&>(), 0 ) ) )
{
  my_swap_( x, y, 0 );
}

---------------------

Of course, this code can be written with another C++0x feature (e.g. decltype),
I'd prefer to use noexcept when result type is void, because it's simple.


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

* [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not handle function templates well
  2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
@ 2011-04-06 13:37 ` jason at gcc dot gnu.org
  2011-04-07 21:48 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-04-06 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.04.06 13:37:31
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not handle function templates well
  2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
  2011-04-06 13:37 ` [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not " jason at gcc dot gnu.org
@ 2011-04-07 21:48 ` jason at gcc dot gnu.org
  2011-04-08 15:02 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-04-07 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> 2011-04-07 21:48:04 UTC ---
Author: jason
Date: Thu Apr  7 21:48:00 2011
New Revision: 172148

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172148
Log:
    PR c++/48468
    * except.c (build_noexcept_spec): Propagate error_mark_node.
    (finish_noexcept_expr): Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/sfinae11.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/except.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/noexcept02.C


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

* [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not handle function templates well
  2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
  2011-04-06 13:37 ` [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not " jason at gcc dot gnu.org
  2011-04-07 21:48 ` jason at gcc dot gnu.org
@ 2011-04-08 15:02 ` jason at gcc dot gnu.org
  2011-04-12 14:33 ` jason at gcc dot gnu.org
  2011-06-08 21:40 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-04-08 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-04-08 15:02:22 UTC ---
Author: jason
Date: Fri Apr  8 15:02:16 2011
New Revision: 172194

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172194
Log:
    PR c++/48468
    * except.c (build_noexcept_spec): Propagate error_mark_node.
    (finish_noexcept_expr): Likewise.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/sfinae11.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/except.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/noexcept02.C


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

* [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not handle function templates well
  2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
                   ` (2 preceding siblings ...)
  2011-04-08 15:02 ` jason at gcc dot gnu.org
@ 2011-04-12 14:33 ` jason at gcc dot gnu.org
  2011-06-08 21:40 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-04-12 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.1

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-04-12 14:33:15 UTC ---
Fixed for 4.6.1.


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

* [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not handle function templates well
  2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
                   ` (3 preceding siblings ...)
  2011-04-12 14:33 ` jason at gcc dot gnu.org
@ 2011-06-08 21:40 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-08 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-08 21:39:50 UTC ---
Note that the fix I just checked in for 49107 delays substitution into
noexcept-specifications, so they are no longer usable for SFINAE.


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

end of thread, other threads:[~2011-06-08 21:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-05 18:45 [Bug c++/48468] New: [C++0x][SFINAE] noexcept operator does handle function templates well gintensubaru at gmail dot com
2011-04-06 13:37 ` [Bug c++/48468] [C++0x][SFINAE] noexcept operator does not " jason at gcc dot gnu.org
2011-04-07 21:48 ` jason at gcc dot gnu.org
2011-04-08 15:02 ` jason at gcc dot gnu.org
2011-04-12 14:33 ` jason at gcc dot gnu.org
2011-06-08 21:40 ` jason at gcc dot gnu.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).