gcc - C++ - What is a "type transparent class"? -
using gcc compile program includes support decimal data types, encountered following error:
error: type transparent class 'std::decimal::decimal32' has base classes
a quick @ gcc's source tree shows error message found in gcc/cp/class.c
.
what "type transparent class"? why error such class have "base classes"?
reading source code of gcc bit more, in semantics.c
:
if (tree_code (t) == record_type && !processing_template_decl) { tree ns = type_context (t); if (ns && tree_code (ns) == namespace_decl && decl_context (ns) == std_node && decl_name (ns) && !strcmp (identifier_pointer (decl_name (ns)), "decimal")) { const char *n = type_name_string (t); if ((strcmp (n, "decimal32") == 0) || (strcmp (n, "decimal64") == 0) || (strcmp (n, "decimal128") == 0)) type_transparent_aggr (t) = 1; } }
this code means type marked transparent if:
- it struct, not template;
- and @ namespace level, , namespace
std::decimal
. - and named
decimal32
,decimal64
ordecimal128
.
in class.c
there error check encountered, , few more.
and in mangle.c
:
/* according c++ abi, library classes passed same scalar type of single member , use same mangling. */ if (tree_code (type) == record_type && type_transparent_aggr (type)) type = tree_type (first_field (type));
the comment key here. think means transparent type replaced type of fist (and only) member, can used anywhere first member can. example, in include/decimal
class std::decimal::decimal32
has single field of type __decfloat32
(from previous typedef float __decfloat32 __attribute__((mode(sd)));
), function takes __decfloat32
can take std::decimal::decimal32
, vice-versa. function decoration done same. idea make classes abi compatible c types _decimal32
, _decimal64
, _decimal128
.
now, how getting class decimal32
base classes? guess including incompatible (maybe older) header files, totally different implementation.
update
after investigation, looks guess abi , function decoration right. following code:
#include <decimal/decimal> using namespace std::decimal; //this synonym of c99 _decimal32, not directly available in c++ typedef float decimal32 __attribute__((mode(sd))); void foo(decimal32 a) {} void foo(decimal32 a) {}
gives curious error:
/tmp/ccr61gna.s: assembler messages: /tmp/ccr61gna.s:1291: error: symbol `_z3foodf' defined
that is, compiler front-end sees no problem in overload , emits asm code, since both functions decorated same assembler fails.
now, non-conformance of gcc, ben voigt suggests in comments? don't know... should able write overloaded functions 2 different types want. otoh, impossible decimal32
type without using compiler extension, meaning of type implementation defined...
Comments
Post a Comment