https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112620

            Bug ID: 112620
           Summary: Changes to the referenced object in exception handler
                    are lost after rethrow
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include <cstdio>

int main() {
    int i;
    try {
        try {
            throw (int*)0;
        } catch (int*& p) {
            p = &i;
            throw;
        }
    }
    catch (int*& p) {
        printf("%p", (void*)p);
    }
}

prints some not-null value in Clang and MSVC, which is correct according to
https://eel.is/c++draft/except.handle#15

> When the handler declares a reference to an object, any changes to the 
> referenced object are changes to the exception object and will have effect 
> should that object be rethrown.

But GCC prints (nil) here. Online demo: https://godbolt.org/z/n6s6bc17s

Reply via email to