public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56208] New: sizeof sfinae fails to work
@ 2013-02-04 19:38 daniel.kruegler at googlemail dot com
  2013-02-04 19:54 ` [Bug c++/56208] " daniel.kruegler at googlemail dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-04 19:38 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56208
           Summary: sizeof sfinae fails to work
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com


The following program becomes rejected when compiled with gcc 4.8.0 trunk using
the flags:

-Wall -pedantic

(with or without -std=c++11)

//--------------------------------
struct ostream {
  ostream& operator<<(int);
};

struct sfinae_base {

  typedef char one;
  typedef char (&two)[2];

  template<class T>
  static T make();

  template<unsigned> struct ok { typedef int type; };

  template<class U, class T>
  static one test(typename ok<sizeof(
    make<U>() << make<T>()
  )>::type);

  template<class, class>
  static two test(...);

};

template<class T>
struct is_printable : private sfinae_base
{
  enum { value = sizeof(test<ostream&, T>(0)) == sizeof(one) };
};

typedef int ok[is_printable<int>::value ? 1 : -1];

int main() {}
//--------------------------------

"Compilation finished with errors:
source.cpp:31:49: error: size of array 'ok' is negative
typedef int ok[is_printable<int>::value ? 1 : -1];
^"

It worked with gcc 4.7.2 (also with Clang 3.2 or Intel-13), so this looks like
a regression to me. Operator<< is not the only one, I also noted problems with
other operators (such as binary plus).


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

* [Bug c++/56208] sizeof sfinae fails to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
@ 2013-02-04 19:54 ` daniel.kruegler at googlemail dot com
  2013-02-04 19:57 ` daniel.kruegler at googlemail dot com
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-04 19:54 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-04 19:54:47 UTC ---
I just notice that the problem is not restricted to sizeof sfinae. In fact if
we define the first test overload as follows:

template<class U, class T>
  static one test(decltype(
    (make<U>() << make<T>()), 0
  ));

the same regression problem occurs. I'm confused.


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

* [Bug c++/56208] sizeof sfinae fails to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
  2013-02-04 19:54 ` [Bug c++/56208] " daniel.kruegler at googlemail dot com
@ 2013-02-04 19:57 ` daniel.kruegler at googlemail dot com
  2013-02-04 20:24 ` [Bug c++/56208] [4.8 Regression] " paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-04 19:57 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-04 19:57:18 UTC ---
The actually tested gcc version was 4.8.0 20130127 (experimental)


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

* [Bug c++/56208] [4.8 Regression] sizeof sfinae fails to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
  2013-02-04 19:54 ` [Bug c++/56208] " daniel.kruegler at googlemail dot com
  2013-02-04 19:57 ` daniel.kruegler at googlemail dot com
@ 2013-02-04 20:24 ` paolo.carlini at oracle dot com
  2013-02-04 21:10 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail " daniel.kruegler at googlemail dot com
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-04 20:24 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-02-04
            Summary|sizeof sfinae fails to work |[4.8 Regression] sizeof
                   |                            |sfinae fails to work
     Ever Confirmed|0                           |1

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-04 20:23:52 UTC ---
Let's mark it as such then.


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (2 preceding siblings ...)
  2013-02-04 20:24 ` [Bug c++/56208] [4.8 Regression] " paolo.carlini at oracle dot com
@ 2013-02-04 21:10 ` daniel.kruegler at googlemail dot com
  2013-02-05  6:37 ` daniel.kruegler at googlemail dot com
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-04 21:10 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.8 Regression] sizeof     |[4.8 Regression] Some
                   |sfinae fails to work        |classic sfinae cases fail
                   |                            |to work

--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-04 21:10:19 UTC ---
Here are two further variants of the first overload that fail to work since
4.8.0 trunk:

(a)
  template<class> struct res { typedef one type; };

  template<class U, class T>
  static typename res<decltype(make<U>() << make<T>())>::type
  test(int);

(b)
  template<class> struct res { typedef one type; };

  template<class U, class T>
  static one
  test(typename res<decltype(make<U>() << make<T>())>::type*);

Obviously the actual problem is not related to sizeof, so I changed the issue
title accordingly.


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (3 preceding siblings ...)
  2013-02-04 21:10 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail " daniel.kruegler at googlemail dot com
@ 2013-02-05  6:37 ` daniel.kruegler at googlemail dot com
  2013-02-05  9:15 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-05  6:37 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-05 06:37:06 UTC ---
I think I found the problem, the root is actually not related to sfinae
(fortunately), but to the way how name-lookup in classes work in gcc. The
problem can be fixed (as a workaround), if we move the static member function

template<class T>
static T make();

into namespace scope (as non-member function). I apologize for the lengthy
thread within this issue. But it nonetheless is a regression, because that
name-lookup worked correctly in previous versions of gcc.


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (4 preceding siblings ...)
  2013-02-05  6:37 ` daniel.kruegler at googlemail dot com
@ 2013-02-05  9:15 ` rguenth at gcc dot gnu.org
  2013-02-05  9:50 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-02-05  9:15 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.0


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (5 preceding siblings ...)
  2013-02-05  9:15 ` rguenth at gcc dot gnu.org
@ 2013-02-05  9:50 ` paolo.carlini at oracle dot com
  2013-02-05 11:26 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-05  9:50 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-05 09:50:11 UTC ---
Thanks Daniel. Next, we have to figure out which commit broke such lookups. I
can work on that today (if nobody beats me)


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (6 preceding siblings ...)
  2013-02-05  9:50 ` paolo.carlini at oracle dot com
@ 2013-02-05 11:26 ` paolo.carlini at oracle dot com
  2013-02-05 11:35 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-05 11:26 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-05 11:25:46 UTC ---
Narrowed to r190095 - r190842 so far.


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (7 preceding siblings ...)
  2013-02-05 11:26 ` paolo.carlini at oracle dot com
@ 2013-02-05 11:35 ` jakub at gcc dot gnu.org
  2013-02-05 19:03 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-05 11:35 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-05 11:35:35 UTC ---
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190664


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (8 preceding siblings ...)
  2013-02-05 11:35 ` jakub at gcc dot gnu.org
@ 2013-02-05 19:03 ` jason at gcc dot gnu.org
  2013-02-05 19:09 ` daniel.kruegler at googlemail dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-05 19:03 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (9 preceding siblings ...)
  2013-02-05 19:03 ` jason at gcc dot gnu.org
@ 2013-02-05 19:09 ` daniel.kruegler at googlemail dot com
  2013-02-06  3:34 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work due to access problems jason at gcc dot gnu.org
  2013-02-06  3:51 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-05 19:09 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-05 19:09:15 UTC ---
Further data about the root of the problem: It seems actually to be an access
problem, the requirements for reproducing seem to be:

1) Some class B derives *privately* from a base class A

2) B refers to some function template f2 that refers to another dependent
function template f1 both in class scope of A (It doesn't matter whether these
function are actually public in A)

A reduced example is as follows:

//---------------------------
struct A {
   template<class T>
   static int f1();

   template<class T>
   static int f2(char(*)[sizeof(f1<T>())]);
};

struct B : private A {
   enum { value = sizeof(f2<int>(0)) };
};
//---------------------------

"Compilation finished with errors:
source.cpp:10:35: error: no matching function for call to 'B::f2(int)'
enum { value = sizeof(f2<int>(0)) };
^
source.cpp:10:35: note: candidate is:
source.cpp:6:15: note: template<class T> static int A::f2(char (*)[sizeof
(f1<T>())])
static int f2(char(*)[sizeof(f1<T>())]);
^
source.cpp:6:15: note: template argument deduction/substitution failed:
source.cpp: In substitution of 'template<class T> static int A::f2(char
(*)[sizeof (f1<T>())]) [with T = int]':
source.cpp:10:35: required from here
source.cpp:3:15: error: 'static int A::f1() [with T = int]' is inaccessible
static int f1();
^
source.cpp:6:39: error: within this context
static int f2(char(*)[sizeof(f1<T>())]);
^"


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work due to access problems
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (10 preceding siblings ...)
  2013-02-05 19:09 ` daniel.kruegler at googlemail dot com
@ 2013-02-06  3:34 ` jason at gcc dot gnu.org
  2013-02-06  3:51 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-06  3:34 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-06 03:33:52 UTC ---
Author: jason
Date: Wed Feb  6 03:33:45 2013
New Revision: 195779

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195779
Log:
    PR c++/56208
    * pt.c (fn_type_unification): Discard any access checks from
    substituting explicit args.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/sfinae43.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c


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

* [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work due to access problems
  2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
                   ` (11 preceding siblings ...)
  2013-02-06  3:34 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work due to access problems jason at gcc dot gnu.org
@ 2013-02-06  3:51 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-06  3:51 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-06 03:51:00 UTC ---
Fixed.


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

end of thread, other threads:[~2013-02-06  3:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-04 19:38 [Bug c++/56208] New: sizeof sfinae fails to work daniel.kruegler at googlemail dot com
2013-02-04 19:54 ` [Bug c++/56208] " daniel.kruegler at googlemail dot com
2013-02-04 19:57 ` daniel.kruegler at googlemail dot com
2013-02-04 20:24 ` [Bug c++/56208] [4.8 Regression] " paolo.carlini at oracle dot com
2013-02-04 21:10 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail " daniel.kruegler at googlemail dot com
2013-02-05  6:37 ` daniel.kruegler at googlemail dot com
2013-02-05  9:15 ` rguenth at gcc dot gnu.org
2013-02-05  9:50 ` paolo.carlini at oracle dot com
2013-02-05 11:26 ` paolo.carlini at oracle dot com
2013-02-05 11:35 ` jakub at gcc dot gnu.org
2013-02-05 19:03 ` jason at gcc dot gnu.org
2013-02-05 19:09 ` daniel.kruegler at googlemail dot com
2013-02-06  3:34 ` [Bug c++/56208] [4.8 Regression] Some classic sfinae cases fail to work due to access problems jason at gcc dot gnu.org
2013-02-06  3:51 ` 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).