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
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2024-05-13 11:29 UTC | newest]

Thread overview: 9+ 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
2024-05-13 11:29 ` rguenth 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).