User account creation filtered due to spam.

Bug 26217 - The <stdexcept> header is not setting default visibility
Summary: The <stdexcept> header is not setting default visibility
Status: RESOLVED DUPLICATE of bug 19664
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 04:56 UTC by Dave Dribin
Modified: 2006-02-11 17:14 UTC (History)
21 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Program to demonstrate error. (199 bytes, text/plain)
2006-02-11 04:59 UTC, Dave Dribin
Details
This is a patch against std_stdexcept.h. (262 bytes, patch)
2006-02-11 05:45 UTC, Dave Dribin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Dribin 2006-02-11 04:56:55 UTC
Here is my gcc information:

% gcc -v
Using built-in specs.
Target: powerpc-apple-darwin8
Configured with: /private/var/tmp/gcc/gcc-5250.obj~12/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.1 (Apple Computer, Inc. build 5250)

Here is the code that reproduces the error:

--- snip ---
#include <iostream>
#include <vector>
#include <stdexcept>

int main (int argc, char * const argv[]) {
    try {
        std::vector<int> intVector;
        intVector.at(0);
    }
    catch (std::out_of_range &) {
        std::cout << "Caught std::out_of_range" << std::endl;
    }
    
    std::cout << "Finished normally" << std::endl;
    return 0;
}
--- snip ---

Here is the error output:

% g++ -fvisibility=hidden -o catch main.cpp
% ./catch
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check
zsh: abort      ./catch
%

Here is the expected output:

% g++ -o catch main.cpp                    
% ./catch
Caught std::out_of_range
Finished normally
%

This problem occurs because std::out_of_range is not marked with default visibility.  This issue is documented here (see the section on Problems with C++ exceptions):

  http://gcc.gnu.org/wiki/Visibility

The <stdexcept> header file needs to be wrapped in:

#pragma GCC visibility push(default)
...
#pragma GCC visibility pop

Just like <exception> is.  This can be verified by modifying the program above as:

--- snip ---
#include <iostream>
#include <vector>
#pragma GCC visibility push(default)
#include <stdexcept>
#pragma GCC visibility pop

int main (int argc, char * const argv[]) {
    try {
        std::vector<int> intVector;
        intVector.at(0);
    }
    catch (std::out_of_range &) {
        std::cout << "Caught std::out_of_range" << std::endl;
    }
    
    std::cout << "Finished normally" << std::endl;
    return 0;
}
--- snip ---
Comment 1 Dave Dribin 2006-02-11 04:59:51 UTC
Created attachment 10819 [details]
Program to demonstrate error.

To trigger the error:

% g++ -fvisibility=hidden -o catch main.cpp
% ./catch
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check
zsh: abort      ./catch
%
Comment 2 Dave Dribin 2006-02-11 05:45:30 UTC
Created attachment 10820 [details]
This is a patch against std_stdexcept.h.

This patch sets visibility to default for all exceptions declared.
Comment 3 Paolo Carlini 2006-02-11 09:27:56 UTC
This is a known issue:

  http://gcc.gnu.org/ml/libstdc++/2005-12/msg00181.html
Comment 4 Andrew Pinski 2006-02-11 17:14:45 UTC

*** This bug has been marked as a duplicate of 19664 ***