14

Simple question: If change this:

void someMethod();

to

void someMethod() noexcept;

will it break binary compatibility, or does the method signature remain the same?

Justin
  • 24,288
  • 12
  • 92
  • 142
Felix
  • 6,885
  • 1
  • 29
  • 54
  • 5
    [Since C++17, "The noexcept-specification is a part of the function type". Before C++17, "The noexcept-specification is not a part of the function type"](https://en.cppreference.com/w/cpp/language/noexcept_spec) – Justin Jul 19 '18 at 18:23
  • 3
    @Justin Even though it's a part of a function type, it [don't seem to affect](https://godbolt.org/g/QosEfk) mangled names on GCC nor on Clang. – HolyBlackCat Jul 19 '18 at 18:28
  • @HolyBlackCat that would be unspecified, so relying on that is dangerous. – SergeyA Jul 19 '18 at 18:32
  • @Justin this is a perfect answer, why posting it as a comment? – SergeyA Jul 19 '18 at 18:32
  • 4
    The C++ standard does not define the Binary Interface. So this is not answerable in the general case. It may work for a particular compiler implementation but that does not provide any guarantee that it will work for future versions of the compiler or other compilers. – Martin York Jul 19 '18 at 19:54
  • 2
    @Justin you left out this part: "*Functions differing only in their exception specification cannot be overloaded (just like the return type, **exception specification is part of function type, but not part of the function signature**) (since C++17).*" – Remy Lebeau Jul 19 '18 at 20:03

1 Answers1

4

Does the method signature remain the same ?

Yes. https://en.cppreference.com/w/cpp/language/noexcept_spec :

Functions differing only in their exception specification cannot be overloaded (just like the return type, exception specification is part of function type, but not part of the function signature) (since C++17).

Will it break binary compability ?

Probably not, but standard doesn't guarentee anything (AFAIK).

darune
  • 10,480
  • 2
  • 24
  • 62
  • 4
    You've said "no", but then quoted part of the spec which implies the answer is "yes". :) " _exception specification is .. not part of the function signature_" - therefore, adding `noexcept` shouldn't change the function signature, and it should remain the same. – davmac Sep 20 '18 at 13:42
  • @davmac Your right, it should have been yes, good catch. Fixed now. – darune Sep 21 '18 at 08:45