[Bug c++/56004] Possible bug with decltype and access modifer order

david.irvine at maidsafe dot net gcc-bugzilla@gcc.gnu.org
Wed Jan 16 18:17:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56004

--- Comment #4 from David Irvine <david.irvine at maidsafe dot net> 2013-01-16 18:16:58 UTC ---
I see

In my case in a simpler version than posted 

this compiles fine  

template <class T>
class Synchronised {
    public:
        Synchronised(T t = T{}) : t_{t} {}
        template <typename F>
        auto operator()(F f) const -> decltype(f(t_)) {
            std::lock_guard<std::mutex> lock{mutex_};
            return f(t_);
        }
        private: // place this before public: and this object compiles
            mutable T t_;
            mutable std::mutex mutex_;
};

Fails and swapping private to be declared before public works ! as below

This will not compile 

template <class T>
class Synchronised {
      private: // place this before public: and this object compiles
            mutable T t_;
            mutable std::mutex mutex_;

    public:
        Synchronised(T t = T{}) : t_{t} {}
        template <typename F>
        auto operator()(F f) const -> decltype(f(t_)) {
            std::lock_guard<std::mutex> lock{mutex_};
            return f(t_);
        }
  };

I think you are saying the same thing but this is what I mean by private coming
before public (changing accessors or their order). I think it is the only
situation I have encountered this.



More information about the Gcc-bugs mailing list