Patchwork [C++,testcase,committed] Add SFINAE testcase

login
register
mail settings
Submitter Paolo Carlini
Date June 23, 2013, 11:38 p.m.
Message ID <51C78700.7020509@oracle.com>
Download mbox | patch
Permalink /patch/253612/
State New
Headers show

Comments

Paolo Carlini - June 23, 2013, 11:38 p.m.
Hi,

I added to mainline the testcase in Comment 16 of PR51213.

Thanks,
Paolo.

/////////////////////
2013-06-23  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp0x/sfinae47.C: New.

Patch

Index: g++.dg/cpp0x/sfinae47.C
===================================================================
--- g++.dg/cpp0x/sfinae47.C	(revision 0)
+++ g++.dg/cpp0x/sfinae47.C	(working copy)
@@ -0,0 +1,25 @@ 
+// Source: Comment 16 of PR51213
+// { dg-do compile { target c++11 } }
+
+template <class T>
+T && declval();
+
+template <class T>
+constexpr auto hasSize(int) -> decltype(declval<T&>().size(), bool())
+{ return true; }
+
+template <class T>
+constexpr bool hasSize(...)
+{ return false; }
+
+struct A
+{
+  int size();
+};
+
+struct B : private A
+{
+};
+
+static_assert(hasSize<A>(0),  "A");
+static_assert(!hasSize<B>(0), "B");