Index: cp/decl.c =================================================================== --- cp/decl.c (revision 207234) +++ cp/decl.c (working copy) @@ -6709,8 +6709,11 @@ get_dso_handle_node (void) ptr_type_node); #ifdef HAVE_GAS_HIDDEN - DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN; - DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1; + if (dso_handle_node != error_mark_node) + { + DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN; + DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1; + } #endif return dso_handle_node; Index: testsuite/g++.dg/init/dso_handle2.C =================================================================== --- testsuite/g++.dg/init/dso_handle2.C (revision 0) +++ testsuite/g++.dg/init/dso_handle2.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/58846 + +extern "C" { char* __dso_handle; } + +struct A +{ + ~A(); +}; + +A a; // { dg-error "conflicting declaration" }