lmi
[Top][All Lists]
Advanced

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

Re[2]: [lmi] still MSVC compilation problems


From: Vadim Zeitlin
Subject: Re[2]: [lmi] still MSVC compilation problems
Date: Tue, 24 Jun 2008 14:09:48 +0200

On Tue, 24 Jun 2008 11:59:02 +0000 Greg Chicares <address@hidden> wrote:

GC> I think your analysis is correct technically. However, whatever
GC> can be expressed within C++'s strong type system, IMO should be,
GC> and I'm extremely prejudiced against void* in particular. If no
GC> compiler needed this workaround, I'd never apply it. Therefore,
GC> I walled it off in msvc-only conditionals, and gave the getter
GC> an unpleasant name.

 Ok, fair enough, thanks.


GC> > Also, placeholder is a private class (and IMO should be
GC> > defined inside some "namespace Private" or "namespace impl") so the unsafe
GC> > "void *get()" shouldn't be used from anywhere else.
GC> 
GC> I know boost does that frequently, and I even copied their
GC> practice for a while. But I just don't see how this makes
GC> anything really safer: one can so easily write 'impl::get()'.

 Well, you've surely heard this argument already but the standard
explanation is that when we try to make the code safe we don't really fight
against somebody determined to write wrong code because this fight is lost
in advance, but just against someone who could be honestly mistaken.
Putting a function in a "Private" namespace clearly shows to any
well-intentioned person that it's not supposed to be used from the outside.


GC> > GC> >  Finally, I still have unit test failures after this change:
GC> > GC> [...]
GC> > GC> > but they seem to be due to the difference between the expected and 
real
GC> > GC> > value of std::type::info::name() so I think I should just add tests 
for
GC> > GC> > MSVC into any_member_test.cpp along the existing tests for g++ 
version. Do
GC> > GC> > you see anything wrong with this?
GC> > GC> 
GC> > GC> Nothing wrong with that. Testing the value of std::type::info::name()
GC> > GC> is fragile, but we're already doing it for other compilers, and I'd
GC> > GC> rather not spend time thinking about removing that fragility right 
now.
GC> > 
GC> >  In fact I think it's easy enough to remove this fragility: instead of
GC> > hardcoding the results of std::type_info::name() in the test code we could
GC> > construct the string dynamically using lmi::TypeInfo(). Then there would 
be
GC> > no need for any compiler [version] tests. If you don't object I'd like to
GC> > do this.
GC> 
GC> This sounds like an interesting idea. Let me suggest you show a
GC> concrete example of such a change first

 Here it is. I didn't test this with old g++ yet but it does work (i.e. the
test passes) with g++ 4.1 and MSVC.

--- any_member_test.cpp 2008-01-01 18:30:08 +0000
+++ any_member_test.cpp 2008-06-22 13:38:43 +0000
@@ -353,16 +353,9 @@

     // Test no-such-member diagnostic for both const and non-const
     // subscripting operators.
-
-#if !(defined __GNUC__ && LMI_GCC_VERSION < 40000)
-    std::string err
-        ("Symbol table for class S ascribes no member named 'nonexistent'."
-        );
-#else  // defined __GNUC__ && LMI_GCC_VERSION < 40000
-    std::string err
-        ("Symbol table for class 1S ascribes no member named 'nonexistent'."
-        );
-#endif // defined __GNUC__ && LMI_GCC_VERSION < 40000
+    std::string err("Symbol table for class ");
+    err += lmi::TypeInfo(typeid(S)).Name();
+    err += " ascribes no member named 'nonexistent'.";

     BOOST_TEST_THROW(s_const["nonexistent"], std::runtime_error, err);
     BOOST_TEST_THROW(s      ["nonexistent"], std::runtime_error, err);
@@ -467,11 +460,11 @@
     std::cout << "Testing function template member_cast().\n";
     s.x0.set_str("Test 3");

-#if !(defined __GNUC__ && LMI_GCC_VERSION < 40000)
-    std::string err("Cannot cast from 'int S::*' to 'base_datum'.");
-#else  // defined __GNUC__ && LMI_GCC_VERSION < 40000
-    std::string err("Cannot cast from 'M1Si' to '10base_datum'.");
-#endif // defined __GNUC__ && LMI_GCC_VERSION < 40000
+    std::string err("Cannot cast from '");
+    err += lmi::TypeInfo(typeid(int S::*)).Name();
+    err += "' to '";
+    err += lmi::TypeInfo(typeid(base_datum)).Name();
+    err += "'.";

     BOOST_TEST_THROW(member_cast<base_datum>(s["i0"]), std::runtime_error, 
err);


 Thanks,
VZ





reply via email to

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