Skip to content

Wrong code with throwing const function #50365

@hvdijk

Description

@hvdijk
Bugzilla Link 51021
Version trunk
OS Linux
CC @dwblaikie,@DougGregor,@efriedma-quic,@zygoloid

Extended Description

The GCC developers have clarified that the function attributes const and pure do not imply that the functions do not throw. clang does assume that and as such miscompiles the following program:

  __attribute__((const)) void f() {
    throw 0;
  }

  int main() {
    try {
      f();
    } catch(int i) {
      return 0;
    }

    return 1;
  }

This program should return 0, not 1.

Godbolt link: https://godbolt.org/z/jj1PG7o78

(Please ignore the warning emitted by GCC, 'const' attribute on function returning 'void'; I have reported that as part of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101376.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions