Skip to content

[[noreturn]] false positive when calling a [[noreturn]] constructor #218

Description

@daveedvdv-nvidia

Discussed in #207

Originally posted by ilazaric October 3, 2026

Issue Summary

If a function marked with [[noreturn]] construct an object whose constructor is marked [[noreturn]],
this is not recognized, and an erroneous warning is emitted.

Reproducing Source Code

struct A {
  [[noreturn]] A() { throw 123; }
};

struct B {
  [[noreturn]] B() { A{}; }
};

[[noreturn]] void g() { A{}; }

Command-line Options

cpfe repro.cpp

Type of Issue

[Front End] This code SHOULD NOT warn with these options.

Additional Details

In the example, both B::B() and g() cause the warning to be emitted,
and it is clear they can't actually return because of A::A().

Compiler output:

"<source>", line 6: warning: function declared with "noreturn" does return
    [[noreturn]] B() { A{}; }
                            ^

"<source>", line 9: warning: function declared with "noreturn" does return
  [[noreturn]] void g() { A{}; }
                               ^

Godbolt: https://godbolt.org/z/nGvdedcsG

Also noting that the attribute on A::A() is not fully ignored,
if we remove the throw it warns there (as expected/correct).

Reproducing (Standard) Configuration(s)

linux-gcc-release

Reproducing (Non-standard) Configuration

No response

I acknowledge that:

  • I have checked open issues and existing discussions before filing this report.
  • The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
  • I have reduced the reproducing source code to the best of my ability.
  • I have selected at least one standard configuration or uploaded a non-standard configuration dump.
  • I understand code shared via this form is NOT confidential.
  • I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
  • I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a LICENSE.txt file in my .zip or .tar.gz upload. If I included a LICENSE.txt file, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.

Activity

  1. daveedvdv-nvidia commented on Oct 5, 2026

    @daveedvdv-nvidia
    Author

    Thanks for reporting this, @ilazaric !
    Interested in taking a stab at it?

  2. ilazaric commented on Oct 6, 2026

    @ilazaric
    Contributor

    Yep, I can take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions