Fix create_implicit_typedef calls for contracts and bad_alloc
Corrects how GCC creates implicit typedefs for C++26 source_location and C++98 bad_alloc to resolve issues with contract features and standard library declarat…
This commit addresses an issue in GCC’s C++ frontend where implicit typedefs were not being created correctly for source_location and bad_alloc. By ensuring the TREE_PUBLIC flag is set on these types during their lookup, the compiler can now properly handle C++26 contracts and maintain consistency with C++98 standard library declarations.
In Details
This change modifies gcc/cp/contracts.cc and gcc/cp/decl.cc to address issues with the create_implicit_typedef mechanism, specifically affecting C++26 contracts and the operator new/delete declarations. The lookup_std_type and lookup_std_contracts_type functions now set TREE_PUBLIC on the looked-up types. This ensures that forward declarations of standard library types, such as source_location, are visible externally, which is crucial for features like C++ contracts that rely on these types being properly established in the global scope.
- implicit typedef
- A type definition that is created automatically by the compiler when a type is used but not explicitly declared. This is common for standard library types or types introduced by language features.
- TREE_PUBLIC
- A flag within GCC's internal tree representation that indicates a symbol (like a type or function) is visible in the global scope and can be referenced from other translation units.
- C++26 contracts
- A proposed C++ language feature that allows developers to specify preconditions, postconditions, and invariants for functions. These contracts can be checked at runtime or compile time.
- bad_alloc
- An exception type defined in the C++ standard library, typically thrown by
newwhen memory allocation fails. - forward-declaration
- A declaration of an identifier (e.g., a class or function) that does not define it. It informs the compiler that the identifier exists and specifies its type, allowing it to be used before its full definition.