public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59729] New: C++11 allows type definitions in conditions
@ 2014-01-08 18:48 harald at gigawatt dot nl
  2014-01-08 20:58 ` [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't harald at gigawatt dot nl
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: harald at gigawatt dot nl @ 2014-01-08 18:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59729
           Summary: C++11 allows type definitions in conditions
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: harald at gigawatt dot nl

This came up on stackoverflow, not real code. It may be either a problem in the
standard, a problem in GCC, or even a problem in my reading.

The restriction on type definitions in conditions seems to have been lifted in
C++11. As such, the following program should be accepted:

int main() {
  if (struct S { } *p = 0) { }
}

However, GCC (just like clang) rejects it:

test.cc: In function ‘int main()’:
test.cc:2:16: error: types may not be defined in conditions
   if (struct S { } *p = 0) { }
                ^

Before C++11, this was an undeniably correct error message. [stmt.select]p2
explicitly stated "The type-specifier-seq shall not contain typedef and shall
not declare a new class or enumeration."

At some point, this rule got moved to type-specifier-seq, so the above was
removed, and [dcl.type]p3 now states: "A type-specifier-seq shall not define a
class or enumeration unless it appears in the type-id of an alias-declaration
(7.1.3) that is not the declaration of a template-declaration."

The condition rule then got changed to have a decl-specifier-seq instead of a
type-specifier-seq, per
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#948. There is
nothing to disallow class definitions in a decl-specifier-seq. However, the
issue doesn't mention lifting those restrictions at all, it is only about
allowing constexpr, so the fact that class definitions now seem to be allowed
may be accidental.

Either way, what GCC now implements doesn't appear to match what the standard
says.
>From gcc-bugs-return-439684-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jan 08 18:48:37 2014
Return-Path: <gcc-bugs-return-439684-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 6147 invoked by alias); 8 Jan 2014 18:48:37 -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 6097 invoked by uid 55); 8 Jan 2014 18:48:34 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/59614] [4.9 regression] Explostion in compile time of heavily templated code
Date: Wed, 08 Jan 2014 18:48: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: 4.9.0
X-Bugzilla-Keywords: compile-time-hog
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: jason at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-59614-4-QLvZexo9eC@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59614-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59614-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: 2014-01/txt/msg00826.txt.bz2
Content-length: 780

http://gcc.gnu.org/bugzilla/show_bug.cgi?idY614

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Jan  8 18:48:31 2014
New Revision: 206439

URL: http://gcc.gnu.org/viewcvs?rev 6439&root=gcc&view=rev
Log:
    PR c++/59614
    * class.c (abi_tag_data): Add tags field.
    (check_abi_tags): Initialize it.
    (find_abi_tags_r): Support collecting missing tags.
    (mark_type_abi_tags): Don't look at template args.
    (inherit_targ_abi_tags): New.
    (check_bases_and_members): Use it.
    * cp-tree.h (ABI_TAG_IMPLICIT): New.
    * mangle.c (write_abi_tags): Check it.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/mangle.c
    trunk/gcc/testsuite/g++.dg/abi/abi-tag5.C


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

* [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't
  2014-01-08 18:48 [Bug c++/59729] New: C++11 allows type definitions in conditions harald at gigawatt dot nl
@ 2014-01-08 20:58 ` harald at gigawatt dot nl
  2015-03-19  9:07 ` paolo.carlini at oracle dot com
  2015-03-19  9:08 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: harald at gigawatt dot nl @ 2014-01-08 20:58 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|C++11 allows type           |[DR1732] C++11 allows type
                   |definitions in conditions   |definitions in conditions
                   |                            |and for-range-declarations,
                   |                            |but shouldn't

--- Comment #1 from Harald van Dijk <harald at gigawatt dot nl> ---
As it turns out, this was indeed accidental, and GCC's and clang's behaviour is
what's intended for conditions, according to
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1732. However,
according to that, the intent is to also disallow type definitions in
for-range-declarations, where GCC currently does permit them (and clang rejects
them).

struct S {
  template <typename T>
  operator T() { return T(); }
};

int main() {
  S s[1];
  for (struct T { } t : s) { }
}

Perhaps this should be suspended until the wording is fixed, and reevaluated at
that time?


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

* [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't
  2014-01-08 18:48 [Bug c++/59729] New: C++11 allows type definitions in conditions harald at gigawatt dot nl
  2014-01-08 20:58 ` [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't harald at gigawatt dot nl
@ 2015-03-19  9:07 ` paolo.carlini at oracle dot com
  2015-03-19  9:08 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-19  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-19
     Ever confirmed|0                           |1

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
It's C++14 now.


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

* [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't
  2014-01-08 18:48 [Bug c++/59729] New: C++11 allows type definitions in conditions harald at gigawatt dot nl
  2014-01-08 20:58 ` [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't harald at gigawatt dot nl
  2015-03-19  9:07 ` paolo.carlini at oracle dot com
@ 2015-03-19  9:08 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-19  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Mine.


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

end of thread, other threads:[~2015-03-19  9:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-08 18:48 [Bug c++/59729] New: C++11 allows type definitions in conditions harald at gigawatt dot nl
2014-01-08 20:58 ` [Bug c++/59729] [DR1732] C++11 allows type definitions in conditions and for-range-declarations, but shouldn't harald at gigawatt dot nl
2015-03-19  9:07 ` paolo.carlini at oracle dot com
2015-03-19  9:08 ` paolo.carlini at oracle dot com

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