Project

General

Profile

Bug #9545

Global visibility of C11 functions in C++11 and C++17 in stdlib.h

Added by Aurélien Larcher about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2018-05-21
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:

Description

In stdlib.h the strategy is to declare ISO standard specific functions/types in /usr/include/iso/stdlib_XXX.h for both C and C++ then include them.
If the language is C++ then functions/types are declared in the std namespace in iso/stdlib_XXX.h and only put in the global namespace in stdlib.h.
This is to cope with the requirement that use of C++ functions from C headers requires them to exist both in :: and std::.

For example:

std::size_t is declared in:

http://src.illumos.org/source/xref/illumos-gate/usr/src/head/iso/stdlib_iso.h

then if __cplusplus >= 199711L it is placed in the global namespace as well.

http://src.illumos.org/source/xref/illumos-gate/usr/src/head/stdlib.h#52

Functions defined in stdlib_c11.h are also declared in the std::namespace but there is no corresponding declaration in the global namespace.
This seems to have been the reason why an explicit "using std::aligned_alloc;" was required from gcc-7 onwards in libstdc++-v3/libsupc++/new_opa.cc, as well as the cause of compilation failure for gcc-8.

For C11 functions used in C++11 and C++17 global visibilty seems required in stdlib.h such as:

/* * Allow global visibility for symbols defined in * C++ "std" namespace in <iso/stdlib_c11.h>.
*/
#if __cplusplus >= 201103L
using std::at_quick_exit;
using std::quick_exit;
#endif
#if __cplusplus >= 201703L
using std::aligned_alloc;
#endif

For C++11 functions refer to:

http://en.cppreference.com/w/cpp/utility/program/quick_exit
http://en.cppreference.com/w/cpp/utility/program/at_quick_exit

For C++17 aligned_alloc refer to:

http://en.cppreference.com/w/cpp/memory/c/aligned_alloc

Adding Robert Mustacchi as watcher since he added support for C11.

History

#1

Updated by Electric Monk about 2 years ago

  • % Done changed from 0 to 100
  • Status changed from New to Closed

git commit 0df48811699b83d09c552548effcb1718d6ff1d0

commit  0df48811699b83d09c552548effcb1718d6ff1d0
Author: Aurélien Larcher <aurelien.larcher@gmail.com>
Date:   2018-05-23T02:11:32.000Z

    9545 Global visibility of C11 functions in C++11 and C++17 in stdlib.h
    Reviewed by: Igor Kozhukhov <igor@dilos.org>
    Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
    Reviewed by: Robert Mustacchi <robert.mustacchi@joyent.com>
    Approved by: Gordon Ross <gwr@nexenta.com>

Also available in: Atom PDF