JDK-8367282 : FORBID_C_FUNCTION needs exception spec consistent with library declaration
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-09-09
  • Updated: 2025-09-22
  • Resolved: 2025-09-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26 b16Fixed
Related Reports
Relates :  
Relates :  
Description
The standard libraries for some platforms declare (most) functions noexcept (possibly using compiler-specific notation). C++17 made the exception specification part of the type of the function. As a consequence, some compilers error in some cases where the exception specifications for redeclarations differ.

clang errors if the first declaration doesn't have an exception specification and a later one is noexcept. It doesn't complain in the reverse case. gcc seems to accept differences in either order. (That might be a gcc bug?) Visual Studio seems to reject any difference, regardless of include order.

This means that FORBID_C_FUNCTION needs to be able to provide a declaration that matches the exception specification of the corresponding library declaration. (It's easier to just match the library always, rather than further conditionalize on whether the compiler might complain.)

Comments
AIX note: People using old AIX versions may run into the following issue: forbiddenFunctions.hpp:76:34: error: exception specification in declaration does not match previous declaration FORBID_IMPORTED_C_FUNCTION(void* malloc(size_t size), noexcept, "use os::malloc"); ^ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^ /usr/include/stdlib.h:743:14: note: previous declaration is here ... (rest of output omitted) This is fixed with https://www.ibm.com/support/pages/apar/IJ47798. Works on AIX 7.2.5.205 (tested).
22-09-2025

The fix for this bug is integrated in jdk-26+16-1571.
13-09-2025

Changeset: 4e59c63e Branch: master Author: Kim Barrett <kbarrett@openjdk.org> Date: 2025-09-12 18:57:12 +0000 URL: https://git.openjdk.org/jdk/commit/4e59c63ec5a896a09f61a019e2fc5a2ec75ec40e
12-09-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/27180 Date: 2025-09-10 02:58:31 +0000
10-09-2025