Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc: error in catching C++ exceptions #162714

Open
4 tasks done
jeroen2442 opened this issue Feb 14, 2024 · 25 comments
Open
4 tasks done

gcc: error in catching C++ exceptions #162714

jeroen2442 opened this issue Feb 14, 2024 · 25 comments
Labels
bug Reproducible Homebrew/homebrew-core bug stale No recent activity

Comments

@jeroen2442
Copy link

jeroen2442 commented Feb 14, 2024

brew gist-logs <formula> link OR brew config AND brew doctor output

% brew config
HOMEBREW_VERSION: 4.2.8
ORIGIN: https://github.com/Homebrew/brew
HEAD: eb7338abba43112e16e178d4329d5483d6d8fd6f
Last commit: 2 days ago
Core tap JSON: 14 Feb 18:31 UTC
Core cask tap JSON: 14 Feb 18:31 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: octa-core 64-bit arm_blizzard_avalanche
Clang: 15.0.0 build 1500
Git: 2.43.0 => /opt/homebrew/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.3.1-arm64
CLT: 15.1.0.0.1.1700200546
Xcode: 15.2
Rosetta 2: false

% brew doctor
Your system is ready to brew.

Verification

  • My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

I tried to compile and run the following program, from an online course on C++, about throwing and catching exceptions:

#include <iostream>
 
class Item{
public : 
     Item(){
        std::cout << "Item constructor called" << std::endl; 
     }
     
     ~Item(){
         std::cout << "Item destructor called" << std::endl;
     }
};

 
int main(){
 
    int a{10};
    int b{0};
 
    try{
        Item item; 
        if( b == 0 )
            throw 110;
        a++; 
        b++;
        std::cout << "Code that executes when things are fine" << std::endl;
        
    } catch(int ex){
        std::cout << "Something went wrong. Exception thrown : " << ex <<  std::endl;
    }
 
    return 0;
}

The program ran on a Mac mini M2 machine under Visual Studio Code.

What happened (include all command output)?

The program compiled fine under gcc 13.2.0, installed at /opt/homebrew/bin by homebrew. When I ran it, the output was:

Item constructor called
terminate called after throwing an instance of 'int'

What did you expect to happen?

I expected the following output:

Item constructor called
Item destructor called
Something went wrong. Exception thrown : 110

This is the correct output, and it was produced when I compiled and ran it under Clang. Also, when I ran the program on the online gcc compiler at https://rextester.com/l/cpp_online_compiler_gcc, it gave the same correct output.

Therefore I suspect there is a problem with the brew-installed version.

Step-by-step reproduction instructions (by running brew commands)

brew install gcc

Note: the installed version is reported as 13.2.0.
@jeroen2442 jeroen2442 added the bug Reproducible Homebrew/homebrew-core bug label Feb 14, 2024
@Bo98
Copy link
Member

Bo98 commented Feb 15, 2024

cc @fxcoudert

@jeroen2442
Copy link
Author

I can now add that I tried the same in a virtual macOS machine on my Mac mini M2. I installed it fresh with Parallels Desktop, installed Visual Studio Code on it, and installed gcc through homebrew.

The result was the same as I reported before: abort, with the same message. Clang on the virtual machine ran the program fine till the end.

Hope this helps.

@fxcoudert
Copy link
Member

If someone has an Intel version of the compiler and could test that, it would be helpful.

@SMillerDev
Copy link
Member

Running on a 2018 MacMini on macOS 13:

MacMini1:~ ios-jenkins$ g++-13 ./test.c -o test
MacMini1:~ ios-jenkins$ ./test
Item constructor called
Item destructor called
Something went wrong. Exception thrown : 110

@jeroen2442
Copy link
Author

The following also occurs and may be related. If I run

#include <iostream>

class SomethingIsWrong
{
public:
    SomethingIsWrong(const std::string &s) : m_message(s){}

    // Copy Constructor
    SomethingIsWrong(const SomethingIsWrong &source)
    {
        m_message = source.m_message;
    }

    // Destructor
    ~SomethingIsWrong(){}

    const std::string &what() const
    {
        return m_message;
    }

private:
    std::string m_message;
};

void do_something()
{
    std::cout << "Doing something" << std::endl;
    throw SomethingIsWrong("new exception");
}

int main()
{
    try
    {
        do_something();
    }
    catch (SomethingIsWrong &ex)
    {
        std::cout << "Exception caught : " << ex.what() << std::endl;
    }

    return 0;
}

Clang gives the expected output:

Doing something
Exception caught : new exception

but gcc aborts with:

Doing something
libunwind: _Unwind_GetTextRelBase - _Unwind_GetTextRelBase() not implemented

@fxcoudert
Copy link
Member

Hum, so. I can confirm this is something wrong with GCC 13, and not happening with the development version (which will become GCC 14). With latest GCC, your first example gives:

Doing something
Exception caught : new exception

and the second one:

Item constructor called
Item destructor called
Something went wrong. Exception thrown : 110

So it's a bug in GCC 13, that has been fixed and will probably be backported in the next release of 13 (13.3.0). I'll try to identify which one exactly, to make sure it's backported.

@jeroen2442
Copy link
Author

Thanks for taking care!

@ilg-ul
Copy link

ilg-ul commented Mar 13, 2024

Please note that with CLT 15.3 the GCC 13 build fails (iains/gcc-13-branch#14).

@RischinR

This comment has been minimized.

@NiltonVolpato
Copy link

What's the workaround for this bug for now? I can't install or update a number of things.

@ilg-ul
Copy link

ilg-ul commented Mar 22, 2024

What's the workaround for this bug for now?

Revert to CLT 15.1.

@fxcoudert
Copy link
Member

Thanks to Iain Sandoe's work, a fix is deployed in the branch at https://github.com/iains/gcc-13-branch/tree/gcc-13-3-darwin-pre-0

It will be in Homebrew's GCC 13.3 whenever that is released.

@ilg-ul
Copy link

ilg-ul commented Mar 22, 2024

a fix is deployed ...

Does the fixed gcc also work properly with CLT 15.3?

@fxcoudert
Copy link
Member

Does the fixed gcc also work properly with CLT 15.3?

You have to be more precise: why respect to what specific issue?

@Bo98
Copy link
Member

Bo98 commented Mar 22, 2024

What's the workaround for this bug for now? I can't install or update a number of things.

While I don't know what issue you are getting, based on what you say here your issue is probably not related to this one. The issue suggestions that appear after a failed brew build are not necessarily accurate. This particular bug report does not currently affect the install of any Homebrew package we're aware of.

@ilg-ul
Copy link

ilg-ul commented Mar 22, 2024

You have to be more precise: why respect to what specific issue?

Basically I encountered two issues:

I don't know if they are related, probably not, but it is always good to test.

From my experience, recent CLTs are a moving target, with each recent version there were various issues, and I always test my builds on multiple versions. For instance now I had to revert to CLT 15.1 for my builds to pass.

@fxcoudert
Copy link
Member

@ilg-ul I can confirm both issues are fixed, with Xcode 15.3 / CLT 15.3, in the latest version of the gcc-13 branch by Iain.

@ilg-ul
Copy link

ilg-ul commented Mar 24, 2024

Thank you @fxcoudert for confirming.

Do you plan to update Homebrew GCC 13.2, or wait for 13.3, probably in July? (the xPack releases follow Homebrew releases).

@NiltonVolpato
Copy link

Revert to CLT 15.1.

That worked for me. Thanks!

@Bo98
Copy link
Member

Bo98 commented Mar 26, 2024

13.3, probably in July

Usually will be late April/early May.

@burgerman
Copy link

Thanks to Iain Sandoe's work, a fix is deployed in the branch at https://github.com/iains/gcc-13-branch/tree/gcc-13-3-darwin-pre-0

It will be in Homebrew's GCC 13.3 whenever that is released.

Hi, thank you for sharing this info. Would you mind sharing how we can replace our local version of 13.2.0 with this new version correctly? Actually, I installed open-mpi at my local which relies on GCC. It looks not working when simply uninstalling the GCC. And I failed to reinstall the GCC in homebrew.

@parthokr
Copy link

parthokr commented Mar 29, 2024

Revert to CLT 15.1.

That worked for me. Thanks!

Hi @NiltonVolpato
Can you please provide instructions specifically on how to revert CLT back to 15.1?

EDIT: Just figured out this page lists all versions of CLT and other tools https://developer.apple.com/download/all/?q=command%20line%20tools

@NiltonVolpato
Copy link

Yes. To downgrade to CLT 15.1:

  • Uninstall the old CLT (sudo rm -rf /Library/Developer/CommandLineTools) and maybe Xcode too
  • Download the older version of Command Line Tools (and Xcode)
  • Install CLT from the downloaded package (and optionally install Xcode as well)
    • Do not run xcode-select --install as that will install the latest version!

@apjanke
Copy link
Contributor

apjanke commented Apr 11, 2024

FYI, just so you know what might be coming: looks like the qt@5 (5.15) build is also broken under Xcode 15.3, for what look like different reasons. Dunno if another qt@5 build will ever be needed. Downgrading Xcode to 15.2 fixed for me; didn't need to downgrade the CLT.

Thanks for the instructions on how to downgrade the CLT, @NiltonVolpato! I wasn't able to figure that out myself, and doing so got GCC building for me again.

Copy link
Contributor

github-actions bot commented May 3, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/homebrew-core bug stale No recent activity
Projects
None yet
Development

No branches or pull requests

11 participants