Skip to content
Snippets Groups Projects
  • Jonathan Wakely's avatar
    61bf34d1
    libstdc++: Fix iostream init for Clang on darwin [PR110432] · 61bf34d1
    Jonathan Wakely authored
    
    The __has_attribute(init_priority) check in <iostream> is true for Clang
    on darwin, which means that user code including <iostream> thinks the
    library will initialize the global streams. However, when libstdc++ is
    built by GCC on darwin, the __has_attribute(init_priority) check is
    false, which means that the library thinks that user code will do the
    initialization when <iostream> is included. This means that the
    initialization is never done.
    
    Add an autoconf check so that the header and the library both make their
    decision based on the static properties of GCC at build time, with a
    consistent outcome.
    
    As a belt and braces check, also do the initialization in <iostream> if
    the compiler including that header doesn't support the attribute (even
    if the library also containers the initialization). This might result in
    redundant initialization done in <iostream>, but ensures the
    initialization happens somewhere if there's any doubt about the
    attribute working correctly due to missing linker support.
    
    libstdc++-v3/ChangeLog:
    
    	PR libstdc++/110432
    	* acinclude.m4 (GLIBCXX_CHECK_INIT_PRIORITY): New.
    	* config.h.in: Regenerate.
    	* configure: Regenerate.
    	* configure.ac: Use GLIBCXX_CHECK_INIT_PRIORITY.
    	* include/std/iostream: Use new autoconf macro as well as
    	__has_attribute.
    	* src/c++98/ios_base_init.h: Use new autoconf macro instead of
    	__has_attribute.
    
    Reviewed-by: default avatarPatrick Palka <ppalka@redhat.com>
    (cherry picked from commit fe2651af)
    61bf34d1
    History
    libstdc++: Fix iostream init for Clang on darwin [PR110432]
    Jonathan Wakely authored
    
    The __has_attribute(init_priority) check in <iostream> is true for Clang
    on darwin, which means that user code including <iostream> thinks the
    library will initialize the global streams. However, when libstdc++ is
    built by GCC on darwin, the __has_attribute(init_priority) check is
    false, which means that the library thinks that user code will do the
    initialization when <iostream> is included. This means that the
    initialization is never done.
    
    Add an autoconf check so that the header and the library both make their
    decision based on the static properties of GCC at build time, with a
    consistent outcome.
    
    As a belt and braces check, also do the initialization in <iostream> if
    the compiler including that header doesn't support the attribute (even
    if the library also containers the initialization). This might result in
    redundant initialization done in <iostream>, but ensures the
    initialization happens somewhere if there's any doubt about the
    attribute working correctly due to missing linker support.
    
    libstdc++-v3/ChangeLog:
    
    	PR libstdc++/110432
    	* acinclude.m4 (GLIBCXX_CHECK_INIT_PRIORITY): New.
    	* config.h.in: Regenerate.
    	* configure: Regenerate.
    	* configure.ac: Use GLIBCXX_CHECK_INIT_PRIORITY.
    	* include/std/iostream: Use new autoconf macro as well as
    	__has_attribute.
    	* src/c++98/ios_base_init.h: Use new autoconf macro instead of
    	__has_attribute.
    
    Reviewed-by: default avatarPatrick Palka <ppalka@redhat.com>
    (cherry picked from commit fe2651af)