c++ - Function template modifies parameter declared with top-level const: clang bug? -


the code below compiles correctly on clang 3.8.1-1 on archlinux.

is clang bug?

gcc issue correct warning/error on this.

template <class t> struct bugreproducer{     using size_type = typename t::size_type;      int bug1(size_type count);     int bug2(size_type count) const;     static int bug3(size_type count); };  template <class t> int bugreproducer<t>::bug1(size_type const count){     // bug. must not allowed     count = 5;      // return use result...     return count; }  template <class t> int bugreproducer<t>::bug2(size_type const count) const{     // same const method     count = 5;     return count; }  template <class t> int bugreproducer<t>::bug3(size_type const count){     // same static method     count = 5;     return count; }    struct dummyvector{     using size_type = int; };    int main(){     using bugrepr = bugreproducer<dummyvector>;      bugrepr reproducer;      auto = reproducer.bug1(1);     auto b = reproducer.bug2(1);     auto c = bugrepr::bug3(1);      // return use result...     return + b + c; } 

here how compile:

[nmmm@zenbook hm3]$ clang x.cc -std=c++11 -lstdc++ -wall -wpedantic -wconversion 

clang , c++14 - same result.

[nmmm@zenbook hm3]$ clang x.cc -std=c++14 -lstdc++ -wall -wpedantic -wconversion 

here gcc output:

[nmmm@zenbook hm3]$ gcc x.cc -std=c++11 -lstdc++ -wall -wpedantic -wconversion x.cc: in instantiation of ‘int bugreproducer<t>::bug1(bugreproducer<t>::size_type) [with t = dummyvector; bugreproducer<t>::size_type = int]’: x.cc:46:28:   required here x.cc:13:8: error: assignment of read-only parameter ‘count’   count = 5;   ~~~~~~^~~ x.cc: in instantiation of ‘int bugreproducer<t>::bug2(bugreproducer<t>::size_type) const [with t = dummyvector; bugreproducer<t>::size_type = int]’: x.cc:47:28:   required here x.cc:22:8: error: assignment of read-only parameter ‘count’   count = 5;   ~~~~~~^~~ x.cc: in instantiation of ‘static int bugreproducer<t>::bug3(bugreproducer<t>::size_type) [with t = dummyvector; bugreproducer<t>::size_type = int]’: x.cc:48:20:   required here x.cc:29:8: error: assignment of read-only parameter ‘count’   count = 5;   ~~~~~~^~~ 

yes, bug in clang; filed @ https://llvm.org/bugs/show_bug.cgi?id=30365.

the nature of bug in class template member function definition appearing outside ([class.mfct]/1) class template, type of parameter dependent on class template parameters, clang uses parameter type of declaration rather parameter type of definition differ in topmost cv-qualification. simplified example:

template<class t> struct { void f(typename t::u); }; template<class t> void a<t>::f(typename t::u const i) { = 1; } struct x { using u = int; }; int main() { a<x>{}.f(0); } 

per [dcl.fct]/5 type of i within definition of a<x>::f int const (use of 'const' function parameters):

5 - [...] after producing list of parameter types, top-level cv-qualifiers modifying parameter type deleted when forming function type. [...] [ note: transformation not affect types of parameters. [...] — end note ]


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -