public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/51155] Incorrect sizeof and sizeof... behavior in template partial specialization
Date: Wed, 16 Nov 2011 09:13:00 -0000	[thread overview]
Message-ID: <bug-51155-4-fKahBwPYAJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51155-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-11-16 08:36:52 UTC ---
(In reply to comment #0)
> 14.5.5.8 of n324 states:
> 
> "A partially specialized non-type argument expression shall not involve a
> template parameter of the
> partial specialization except when the argument expression is a simple
> identifier."
> 
> From what I understand, this seems to be broken when using sizeof:
[..]
> template <int a>
> struct foo<sizeof(a), a> { }; // not correct and compiles

The core language is a bit fuzzy here, but this example should be no problem at
all, because sizeof(a) does not actually depend on the value of a, it just
corresponds to the equivalent of sizeof(int), which is fine. I don't think that
gcc should change the compiler behaviour here unless the core language is
better. IMO the corresponding CWG issue is this one:

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1315

I observe that Comeau online accepts this as well.

> Additional bugs when using sizeof.. with a variadic template
> 
> template <int n, int... xs>
> struct foo { };
> 
> // partial specialization:
> template <int... xs>
> struct foo<sizeof...(xs), xs...> { }; // not correct and doesn't compile
>                                       // although it should if sizeof is
> allowed
> 
> template <int... xs>
> struct foo<sizeof(xs), xs...> { };    // not correct and compiles
>                                       // sizeof(xs) evaluates to sizeof(int)
>                                       // which is incorrect

I agree that this should be ill-formed, it looks as if gcc incorrectly performs
an implicit unpacking of the parameter pack xs here. It does so correctly
within the body of a class template.


  reply	other threads:[~2011-11-16  8:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-16  7:31 [Bug c++/51155] New: sizeof and sizeof... " pubby.8 at gmail dot com
2011-11-16  9:13 ` daniel.kruegler at googlemail dot com [this message]
2021-06-01 14:28 ` [Bug c++/51155] Incorrect sizeof and sizeof... behavior " ppalka at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-51155-4-fKahBwPYAJ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).