https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121549
Bug ID: 121549 Summary: Bad diagnostic when calling malloc with -xc++ -ffreestanding Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: blubban at gmail dot com Target Milestone: --- #include <cstdlib> void* foo() { return malloc(8); } -xc++ -ffreestanding (does not reproduce with -xc) Result: <source>: In function 'void* foo()': <source>:3:22: error: 'malloc' was not declared in this scope 3 | void* foo() { return malloc(8); } | ^~~~~~ <source>:2:1: note: 'malloc' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>' 1 | #include <cstdlib> +++ |+#include <cstdlib> 2 | Compiler returned: 1 I'm not sure what adding another #include <cstdlib> would accomplish. (GCC is correct to reject malloc under -ffreestanding, this is just a bad diagnostic. Feel free to deprioritize.)