lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] -Wno-mismatched-tags please


From: Greg Chicares
Subject: [lmi] -Wno-mismatched-tags please
Date: Fri, 20 May 2016 04:24:17 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0

  https://github.com/vadz/lmi/pull/31
| Consistently use either "struct" or "class" in both forward declarations of
| the test class and when defining it to avoid clang -Wmismatched-tags warning.

Not a defect.

| I'm not sure what was the intention here as some test classes are forward-
| declared as structs but defined as classes while it's the converse for the
| others.

Example:

$grep RttiLmiTest *.?pp
rtti_lmi.hpp:class RttiLmiTest;
rtti_lmi.hpp:    friend class ::RttiLmiTest;
rtti_lmi_test.cpp:struct RttiLmiTest
rtti_lmi_test.cpp:void RttiLmiTest::TestTypeInfo()
rtti_lmi_test.cpp:    RttiLmiTest::TestTypeInfo();

For forward declarations and friend declarations, I prefer the more general
key "class": when I write them, I may not yet sure whether I'll define a
class or a struct. In the case of 'any_member_test', I suppose I felt sure
that I'd use a struct, and that's okay; all the others use "class".

For the actual definition, I prefer "struct" in cases like this:

struct RttiLmiTest
{
    class X {};
    static void TestTypeInfo();
};

Here, there are no member data, and member functions are all static.
All of these unit-test classes are like that except one. 'LoadsTest' is the
exception: it has data members, a ctor, and so on, so if I were writing it
today I'd certainly define it as a "class"; that's the only place where I
have any regret at all, but I don't regret it enough to change it.

There's no good reason to change any of this. See the erratum for pages
153-154 here:
  http://www.gotw.ca/publications/xc++-errata.htm
| It's perfectly legal and standards-conforming to forward-declare a class
| as a struct and vice versa. In most of the book I've tended to avoid doing
| that, though. Why? Only because some compilers are buggy and still don't
| get this right -- e.g., by name-mangling a class and a struct differently,
| which will cause the linker to fail to match them up. Such compiler bugs
| really are bugs and are wrong, but they're common enough that we might as
| well avoid the issue by not relying on this standard feature. Sigh.

C++98 7.1.5.3/6
| the enum keyword shall be used to refer to an enumeration (_dcl.enum_),
| the union class-key shall be used to refer to a union (_class_),
| and either the class or   struct class-key shall be used to refer to a
| class (_class_) declared using the class or struct class-key.
C++98 9/4
| A structure is a class defined with the class-key struct

AFAICS, this warning is wrong and the clang developers should remove it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]