public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113158] New: Erroneous "looser exception specification" error for class template
@ 2023-12-27 17:38 sim.f.nilsson at gmail dot com
  2023-12-27 19:49 ` [Bug c++/113158] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: sim.f.nilsson at gmail dot com @ 2023-12-27 17:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113158
           Summary: Erroneous "looser exception specification" error for
                    class template
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sim.f.nilsson at gmail dot com
  Target Milestone: ---

The following code is not accepted by GCC 13.2.0 (among other versions):

#include <type_traits>

struct base {
    virtual int f() const = 0;
};

template<typename T>
struct derived : base {
    int f() const noexcept(std::is_nothrow_copy_constructible_v<T>) override
    {
        return sizeof(T);
    }
};

int g()
{
    return derived<double>{}.f();
}

I've tested versions 9 through 13 and trunk. Version 9.5 seems to be the last
version that accepts the code. The code is accepted by both Clang and MSVC. To
the best of my knowledge Clang and MSVC are correct to accept the code as
base::f is a "potentially throwing function" without the noexcept specifier.

What flags are used when compiling the code does not seem to influence the
behaviour, but for reference I've mostly used '-Wall -Wextra -O1 -std=c++17' in
comparisons.

The following compiler-explorer link also demonstrates the error:
https://compiler-explorer.com/z/1c48Yr76P

Adding 'noexcept(false)' in the base-class declaration of f, or either
'noexcept' or 'noexcept(false)' to the derived definition, makes GCC accept it.

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
@ 2023-12-27 19:49 ` pinskia at gcc dot gnu.org
  2023-12-27 19:55 ` [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Erroneous "looser exception |[11/12/13/14 Regression]
                   |specification" error for    |Erroneous "looser exception
                   |class template              |specification" error for
                   |                            |class template
      Known to work|                            |9.5.0
   Target Milestone|---                         |11.5
      Known to fail|                            |10.1.0

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
  2023-12-27 19:49 ` [Bug c++/113158] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-12-27 19:55 ` pinskia at gcc dot gnu.org
  2024-01-02 21:05 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 19:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-12-27
            Summary|[11/12/13/14 Regression]    |[11/12/13/14 Regression]
                   |Erroneous "looser exception |Erroneous "looser exception
                   |specification" error for    |specification" error for
                   |class template              |class template and depedent
                   |                            |noexcept value

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

Reduced testcase:
```
template<typename T>
struct V {
  static constexpr bool t = false;
};
struct base {
    virtual int f() = 0;
};

template<typename T>
struct derived : base {
    int f() noexcept(V<T>::t) override;
};
```

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
  2023-12-27 19:49 ` [Bug c++/113158] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2023-12-27 19:55 ` [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value pinskia at gcc dot gnu.org
@ 2024-01-02 21:05 ` ppalka at gcc dot gnu.org
  2024-01-09 14:39 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-02 21:05 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
           Keywords|needs-bisection             |

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r10-1280-g78f7607db4c53f

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
                   ` (2 preceding siblings ...)
  2024-01-02 21:05 ` ppalka at gcc dot gnu.org
@ 2024-01-09 14:39 ` mpolacek at gcc dot gnu.org
  2024-02-16 17:16 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-09 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
                   ` (3 preceding siblings ...)
  2024-01-09 14:39 ` mpolacek at gcc dot gnu.org
@ 2024-02-16 17:16 ` mpolacek at gcc dot gnu.org
  2024-02-17 14:29 ` cvs-commit at gcc dot gnu.org
  2024-02-17 14:41 ` [Bug c++/113158] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-16 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
https://gcc.gnu.org/pipermail/gcc-patches/2024-February/645767.html

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

* [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
                   ` (4 preceding siblings ...)
  2024-02-16 17:16 ` mpolacek at gcc dot gnu.org
@ 2024-02-17 14:29 ` cvs-commit at gcc dot gnu.org
  2024-02-17 14:41 ` [Bug c++/113158] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-17 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:876fa432ef4074053fa65b1855e7d43320515576

commit r14-9047-g876fa432ef4074053fa65b1855e7d43320515576
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Feb 15 17:07:43 2024 -0500

    c++: wrong looser excep spec for dep noexcept [PR113158]

    Here we find ourselves in maybe_check_overriding_exception_spec in
    a template context where we can't instantiate a dependent noexcept.
    That's OK, but we have to defer the checking otherwise we give wrong
    errors.

            PR c++/113158

    gcc/cp/ChangeLog:

            * search.cc (maybe_check_overriding_exception_spec): Defer checking
            when a noexcept couldn't be instantiated & evaluated to false/true.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/noexcept83.C: New test.

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

* [Bug c++/113158] [11/12/13 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value
  2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
                   ` (5 preceding siblings ...)
  2024-02-17 14:29 ` cvs-commit at gcc dot gnu.org
@ 2024-02-17 14:41 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-17 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |Erroneous "looser exception |Erroneous "looser exception
                   |specification" error for    |specification" error for
                   |class template and depedent |class template and depedent
                   |noexcept value              |noexcept value

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

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

end of thread, other threads:[~2024-02-17 14:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 17:38 [Bug c++/113158] New: Erroneous "looser exception specification" error for class template sim.f.nilsson at gmail dot com
2023-12-27 19:49 ` [Bug c++/113158] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-12-27 19:55 ` [Bug c++/113158] [11/12/13/14 Regression] Erroneous "looser exception specification" error for class template and depedent noexcept value pinskia at gcc dot gnu.org
2024-01-02 21:05 ` ppalka at gcc dot gnu.org
2024-01-09 14:39 ` mpolacek at gcc dot gnu.org
2024-02-16 17:16 ` mpolacek at gcc dot gnu.org
2024-02-17 14:29 ` cvs-commit at gcc dot gnu.org
2024-02-17 14:41 ` [Bug c++/113158] [11/12/13 " mpolacek 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).