public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66671] New: Failure to create a new family of templates for template alias
@ 2015-06-25 18:20 thiago at kde dot org
  2021-11-10 10:26 ` [Bug c++/66671] " pinskia at gcc dot gnu.org
  2022-11-29  6:38 ` herring at lanl dot gov
  0 siblings, 2 replies; 3+ messages in thread
From: thiago at kde dot org @ 2015-06-25 18:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66671

            Bug ID: 66671
           Summary: Failure to create a new family of templates for
                    template alias
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Whenever you use:

template <typename T>
using Z = Y<T>;

The template Z is different from Y and should be encoded separately. This can
be seen in the example:

====
#include <iostream>

template <template <typename> class>
struct X {
  X() { std::cout << "1"; }
};

template <typename>
struct Y {};

template <typename T>
using Z = Y<T>;

template <>
struct X<Y> {
  X() { std::cout << "2"; }
};

int main() {
  X<Y> x1;
  X<Z> x2;
}
====
(from: http://cppquiz.org/quiz/giveup/117)

With GCC 5.1.1, the above prints "22", whereas it prints "21" with ICC 16,
Clang 3.7 and MSVC 2013. The explanation from the quiz site is given as:

> According to §14.5.7¶1 in the standard, a template alias declaration 
> resolve to a new family of types. The specialization cannot be used, 
> and the first template delcaration is used instead, printing 1.

Disassembly with -O2 -fno-inline shows that Clang and ICC both call different
template specialisations of template class X:

        leaq    16(%rsp), %rdi
        callq   _ZN1XI1YEC2Ev          ; X<Y>::X()
        leaq    8(%rsp), %rdi
        callq   _ZN1XI1ZEC2Ev          ; X<Z>::X()

PS: should X<Z> count as a local type or a global one?
>From gcc-bugs-return-490214-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 18:47:23 2015
Return-Path: <gcc-bugs-return-490214-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 92361 invoked by alias); 25 Jun 2015 18:47:23 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 92323 invoked by uid 48); 25 Jun 2015 18:47:19 -0000
From: "thiago at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66672] New: std::is_same wrong result for captured reference value inside a lambda
Date: Thu, 25 Jun 2015 18:47:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.1.1
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: thiago at kde dot org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone
Message-ID: <bug-66672-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02546.txt.bz2
Content-length: 1850

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66672

            Bug ID: 66672
           Summary: std::is_same wrong result for captured reference value
                    inside a lambda
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Given the following code:

====
#include <iostream>
#include <type_traits>

using namespace std;

int main()
{
  int i, &j = i;
  [=]
  {
    cout << is_same<decltype((j)), int      &>::value
         << is_same<decltype((j)), int const&>::value;
  }();
}
====
(trimmed from http://cppquiz.org/quiz/question/127)

With GCC 5.1, the code will print 10, but it should be 01. Clang 3.6, ICC 16
and MSVC 2015 do compile this as expected. The output 10 would be correct if
the extra set of parentheses weren't there.

The explanation given on the quiz website is:

> Since the expression for decltype is a parenthesized lvalue 
> expression, §7.1.6.2¶4 has this to say: "The type denoted by 
> decltype(e) is (...) T&, where T is the type of e;" As the
> expression occurs inside a const member function, the expression is
> const, and decltype((j)) denotes int const&. See also the example in 
> §5.1.2¶18.
[NB: it's paragraph 19 as of N4431]

The example in that paragraph of the standard matches almost exactly the code
above.

The output is correct with a functor:

====
struct S
{
  S(int &i) : j(i) {}
  void operator()() const
  {
    cout << is_same<decltype((j)), int      &>::value
         << is_same<decltype((j)), int const&>::value;
  };
  int j;    // captured by value
};
int main()
{
  int i;
  S{i}();
}
====
>From gcc-bugs-return-490215-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 18:49:06 2015
Return-Path: <gcc-bugs-return-490215-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 95475 invoked by alias); 25 Jun 2015 18:49:06 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 95392 invoked by uid 48); 25 Jun 2015 18:49:02 -0000
From: "joe.carnuccio at qlogic dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/39121] strange behavior in chained operations
Date: Thu, 25 Jun 2015 18:49:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: major
X-Bugzilla-Who: joe.carnuccio at qlogic dot com
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: INVALID
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-39121-4-BHpAQ5GWJy@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-39121-4@http.gcc.gnu.org/bugzilla/>
References: <bug-39121-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02547.txt.bz2
Content-length: 579

https://gcc.gnu.org/bugzilla/show_bug.cgi?id9121

joe.carnuccio at qlogic dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joe.carnuccio at qlogic dot com

--- Comment #4 from joe.carnuccio at qlogic dot com ---
I have found the following:

This works: c ^= d ^= c ^= d  (where c and d are not pointers)

This fails: *a ^= *b ^= *a ^= *b  (where a and b are pointers)

When compiling using -Os then the failed case now works.


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

* [Bug c++/66671] Failure to create a new family of templates for template alias
  2015-06-25 18:20 [Bug c++/66671] New: Failure to create a new family of templates for template alias thiago at kde dot org
@ 2021-11-10 10:26 ` pinskia at gcc dot gnu.org
  2022-11-29  6:38 ` herring at lanl dot gov
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-10 10:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66671

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-10
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/66671] Failure to create a new family of templates for template alias
  2015-06-25 18:20 [Bug c++/66671] New: Failure to create a new family of templates for template alias thiago at kde dot org
  2021-11-10 10:26 ` [Bug c++/66671] " pinskia at gcc dot gnu.org
@ 2022-11-29  6:38 ` herring at lanl dot gov
  1 sibling, 0 replies; 3+ messages in thread
From: herring at lanl dot gov @ 2022-11-29  6:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66671

S. Davis Herring <herring at lanl dot gov> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |herring at lanl dot gov

--- Comment #2 from S. Davis Herring <herring at lanl dot gov> ---
CWG1286 suggests that perhaps such a trivial alias template as Z ought to
actually be interchangeable with Y.

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

end of thread, other threads:[~2022-11-29  6:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25 18:20 [Bug c++/66671] New: Failure to create a new family of templates for template alias thiago at kde dot org
2021-11-10 10:26 ` [Bug c++/66671] " pinskia at gcc dot gnu.org
2022-11-29  6:38 ` herring at lanl dot gov

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