[cfe-dev] C vs. C++: Inconsistent type classifications
Doug Gregor
doug.gregor at gmail.com
Thu Nov 20 14:46:12 PST 2008
There are several places where C and C++ have different definitions
for the same type classification terms. For example, "integer types"
in C include enumeration types, but "integer types" in C++ doesn't
include enumeration types. On the other hand, "object types" in C
doesn't include incomplete types, while "object types" in C++ does
include incomplete types.
This presents a dilemma for the Type class, which has methods like
isIntegerType and isObjectType. It isn't clear whether these routines
should follow the C semantics, the C++ semantics, the current language
semantics, or whether we should decide on a case-by-case basis.
The third option turns out to be a bad idea: I prototyped it with
isIntegerType, making it follow the C semantics when we're in C and
the C++ semantics when we're in C++. This is fine for the C-specific
and C++-specific parts of the compiler, but it becomes very messy in
the common subset of C and C++. Let's not go there.
Personally, I favor following the C++ semantics, because I find the
C++ classifications more natural ("integer" type doesn't scream
"enumeration" for me, and whether or not we've seen a definition for a
type shouldn't affect what kind of type it is), and of course, in the
long run, the majority of the code in Clang is going to go toward
supporting C++.
If we go the C++-semantics route, I'll prepare a patch with at least
these changes:
- isIntegerType will follow the C++ semantics ("false" for enums),
and be renamed to isIntegralType to represent the common term used in
C++
- isSignedIntegerType and isUnsignedIntegerType will change in the same way
- isArithmeticType will follow the C++ semantics.
- add isIntegerOrEnumeralType (if needed, possibly with
signed/unsigned variants) and isArithmeticOrEnumeralType (if needed) ;
this will take some thought to deal with GNU's and C++0x's forward
declaration of enums.
- isObjectType will follow the C++ semantics (true for incomplete
object types)
- add isCompleteObjectType to handle the C semantics where we need
them ("complete object type" is also used in C++)
Any comments? Screams?
- Doug
More information about the cfe-dev
mailing list