Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a bug in GCC?
    primarykey
    data
    text
    <p>EDIT: This is not a bug, just me not knowing about <a href="https://stackoverflow.com/q/4643074/21475">dependent name lookups in templated base classes</a> (which MSVC "helpfully" resolves without errors).</p> <hr> <p>I wrote a functor implementation a while back, and a simple "Event" wrapper that uses it. It compiles fine under MSVC, but GCC gives an error about a member variable in the base class, <code>subscribers</code>, not being declared; changing <code>subscribers</code> to <code>this-&gt;subscribers</code> resolves the issue(!). It appears to happen only with the curiously recurring template pattern, and with partial template specialization.</p> <p>Simplified source (sorry for the mind-bending template usage...):</p> <pre><code>#include &lt;vector&gt; template&lt;typename TEvent&gt; struct EventBase { protected: std::vector&lt;int&gt; subscribers; }; template&lt;typename TArg1 = void, typename TArg2 = void&gt; struct Event : public EventBase&lt;Event&lt;TArg1, TArg2&gt; &gt; { void trigger(TArg1 arg1, TArg2 arg2) const { // Error on next line auto it = subscribers.cbegin(); } }; template&lt;typename TArg1&gt; struct Event&lt;TArg1, void&gt; : public EventBase&lt;Event&lt;TArg1&gt; &gt; { void trigger(TArg1 arg1) const { // Using `this` fixes error(?!) auto it = this-&gt;subscribers.cbegin(); } }; template&lt;&gt; struct Event&lt;void, void&gt; : public EventBase&lt;Event&lt;&gt; &gt; { void trigger() const { // No error here even without `this`, for some reason! auto it = subscribers.cbegin(); } }; int main() { return 0; } </code></pre> <p>Am I invoking undefined behaviour somewhere? Is my syntax somehow wrong? Is this really a bug in GCC? Is it perhaps a known bug? Any insight would be appreciated!</p> <p>More details: Compiled using <code>g++ -std=c++11 main.cpp</code>. I'm using GCC version 4.7.2. Exact error message:</p> <pre><code>main.cpp: In member function ‘void Event&lt;TArg1, TArg2&gt;::trigger(TArg1, TArg2) const’: main.cpp:17:15: error: ‘subscribers’ was not declared in this scope </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload