Re: Potentially bogus warning about anonymous types

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

 



On 16 May 2013 08:38, Nathan Ridge wrote:
> Hello,
>
> A while ago I encountered what I believed to be a bogus warning
> of the form "... uses the anonymous namespace" with GCC 4.8.
>
> I posted http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54060 ,
> and I was told there that:
>
>  1. The warning is meant to say "... uses an anonymous type"
>     rather than "... uses the anonymous namespace".
>  2. Aside from the poor wording, the warning is not bogus
>     because it points out a potential ODR violation.
>
> I recently encountered the same warning in a different situation,
> but I don't see where the potential ODR violation is this time.
> I suspect there may not be one (and thus the warning really is
> bogus in this case), but I wanted to double-check before filing
> a bug.
>
> Here is the code in question:
>
>
> test.cpp:
>
> #include "test.hpp"
>
>
> test.hpp:
>
> template <typename T>
> struct base
> {
>     static const bool value = true;
> };
>
> template <bool>
> struct outer;
>
> template <>
> struct outer<false>
> {
>     template <typename T>
>     struct inner : public base<T>
>     {
>     };
> };
>
> bool foo()
> {
>     auto lambda = [](){};
>     typedef decltype(lambda) Lambda;
>     return outer<false>::inner<Lambda>::value;
> }
>
>
>
> When compiling test.cpp, I get the following warning:
>
> In file included from test.cpp:1:0:
> test.hpp: In instantiation of 'struct outer<false>::inner<foo()::__lambda0>':
> test.hpp:23:39:   required from here
> test.hpp:14:12: warning: 'outer<false>::inner<foo()::__lambda0>' has a base 'base<foo()::__lambda0>' whose type uses the anonymous namespace [enabled by default]
>      struct inner : public base<T>
>             ^
>
>
> Could someone please confirm whether there is an ODR violation
> here, and if so explain what it is?

There is if you include test.hpp in multiple translation units (and
the compiler has to assume you will) because foo() is not declared
inline.  Do that and the warning goes away.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux