public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52809] New: Template non-dependent static_assert diagnostics may confuse
@ 2012-03-31 16:55 potswa at mac dot com
  2012-03-31 16:58 ` [Bug c++/52809] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: potswa at mac dot com @ 2012-03-31 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52809
           Summary: Template non-dependent static_assert diagnostics may
                    confuse
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: potswa@mac.com


A static_assert declaration that does not depend on template parameters will be
detected and reported while parsing the template, before any instantiation.
This is OK because such a template would have no valid instantiation, which
immediately renders the program ill-formed.

In terms of cosmetic QOI, however, it would be better to clarify the messages
for users who don't know all the rules. Intuitively, the assertion shouldn't be
evaluated until instantiation, regardless of dependence. The user might expect
an uninstantiated template to pass through. We should add something like
"error: template MyTemplate cannot have a valid instantiation" after the
static_assert diagnostic.

Example code and result, as currently implemented:

template< bool b >
struct s {
    static_assert( b, "uhoh" );
    static_assert( false, "yikes" );
};

s< false > q;

depassert.cpp:4:1: error: static assertion failed: yikes
depassert.cpp: In instantiation of ‘struct s<false>’:
depassert.cpp:7:12:   required from here
depassert.cpp:3:1: error: static assertion failed: uhoh


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

* [Bug c++/52809] Template non-dependent static_assert diagnostics may confuse
  2012-03-31 16:55 [Bug c++/52809] New: Template non-dependent static_assert diagnostics may confuse potswa at mac dot com
@ 2012-03-31 16:58 ` paolo.carlini at oracle dot com
  2021-08-04  6:29 ` pinskia at gcc dot gnu.org
  2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-31 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-31 16:55:10 UTC ---
If we wanted, I think a simple way to add an inform about a static_assert which
can never be fullfilled, would be adding a flag to finish_static_assert in
order to tell in its body whether is being called from the parser or from pt.c.
Something a bit uncommon, afaik, but seems simple.

Jason, what do you think?


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

* [Bug c++/52809] Template non-dependent static_assert diagnostics may confuse
  2012-03-31 16:55 [Bug c++/52809] New: Template non-dependent static_assert diagnostics may confuse potswa at mac dot com
  2012-03-31 16:58 ` [Bug c++/52809] " paolo.carlini at oracle dot com
@ 2021-08-04  6:29 ` pinskia at gcc dot gnu.org
  2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04  6:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
           Severity|minor                       |enhancement

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

* [Bug c++/52809] Template non-dependent static_assert diagnostics may confuse
  2012-03-31 16:55 [Bug c++/52809] New: Template non-dependent static_assert diagnostics may confuse potswa at mac dot com
  2012-03-31 16:58 ` [Bug c++/52809] " paolo.carlini at oracle dot com
  2021-08-04  6:29 ` pinskia at gcc dot gnu.org
@ 2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-18 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:9944ca17c0766623bce260684edc614def7ea761

commit r13-6133-g9944ca17c0766623bce260684edc614def7ea761
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 10 16:16:45 2023 -0800

    c++: static_assert (false) in template [DR2518]

    For a long time, people have expected to be able to write
    static_assert (false) in a template and only have it diagnosed if the
    template is instantiated, but we (and other implementations) gave an error
    about the uninstantiated template because the standard says that if no
valid
    instantiation of the template is possible, the program is ill-formed, no
    diagnostic required, and we try to diagnose IFNDR things when feasible.

    At the meeting last week we were looking at CWG2518, which wanted to
specify
    that an implementation must not accept a program containing a failing
#error
    or static_assert.  We also looked at P2593, which proposed allowing
    static_assert in an uninstantiated template.  We ended up combining these
    two in order to avoid requiring implementations to reject programs with
    static_assert (false) in uninstantiated templates.

    The committee accepted this as a DR, so I'm making the change to all
    standard modes.  This behavior was also conformant previously, since no
    diagnostic was required in this case.

    We continue to diagnose non-constant or otherwise ill-formed conditions, so
    no changes to existing tests were needed.

            DR 2518
            PR c++/52809
            PR c++/53638
            PR c++/87389
            PR c++/89741
            PR c++/92099
            PR c++/104041
            PR c++/104691

    gcc/cp/ChangeLog:

            * semantics.cc (finish_static_assert): Don't diagnose in
            template context.

    gcc/testsuite/ChangeLog:

            * g++.dg/DRs/dr2518.C: New test.

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

end of thread, other threads:[~2023-02-18 21:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-31 16:55 [Bug c++/52809] New: Template non-dependent static_assert diagnostics may confuse potswa at mac dot com
2012-03-31 16:58 ` [Bug c++/52809] " paolo.carlini at oracle dot com
2021-08-04  6:29 ` pinskia at gcc dot gnu.org
2023-02-18 21:19 ` cvs-commit 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).