public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sim.f.nilsson at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/113158] New: Erroneous "looser exception specification" error for class template
Date: Wed, 27 Dec 2023 17:38:46 +0000	[thread overview]
Message-ID: <bug-113158-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2023-12-27 17:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-27 17:38 sim.f.nilsson at gmail dot com [this message]
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

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-113158-4@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).