Re: GCC 7.2.0 c++ template / typing problem

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

 



On 15 January 2018 at 02:09,  <TPCgcc@xxxxxxxxxxxxxxxxxxx> wrote:
> Dear All,
>         I am attempting to build this application
> http://prdownloads.sourceforge.net/nget/nget-0.27.1.tar.gz?download with gcc
> 7.2.0.  It built faultlessly under GCC 4.2.0 but it fails with these
> (sample) errors under 7.2.0.
>
> g++ -g -O2 -Wall -MMD -MP -DHAVE_CONFIG_H -std=c++1z -Wwrite-strings
> -Wno-deprecated   -c -o etree.o etree.cc
> etree.cc: In instantiation of 'pred<ClassType>* comparison(const string&,
> getterT, T2) [with ClassType = const c_nntp_file; getterT = long unsigned
> int (c_nntp_file::*)() const; T2 = long unsigned int; std::string =
> std::basic_string<char>]':
> etree.cc:200:81:   required from here
> etree.cc:87:73: error: no matching function for call to
> 'new_comparison<template<class T, class T2> struct Op_eq, const
> c_nntp_file>(long unsigned int (c_nntp_file::*&)() const, long unsigned
> int&)'
>   if      (opstr.compare("==")==0) return
> new_comparison<Op_eq,ClassType>(get, v);
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
> etree.cc:78:18: note: candidate: template<template<class A, class B> class
> Op, class ClassType, class RetType> pred<ClassType>* new_comparison(RetType
> ClassType::*, RetType)
>  pred<ClassType> *new_comparison(RetType (ClassType::*member), RetType v){
>                   ^~~~~~~~~~~~~~
> etree.cc:78:18: note:   template argument deduction/substitution failed:
> etree.cc:87:73: note:   deduced conflicting types for parameter 'RetType'
> ('long unsigned int() const' and 'long unsigned int')
>   if      (opstr.compare("==")==0) return
> new_comparison<Op_eq,ClassType>(get, v);
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
> etree.cc:82:18: note: candidate: template<template<class A, class B> class
> Op, class ClassType, class RetType> pred<ClassType>* new_comparison(RetType
> (ClassType::*)(), RetType)
>  pred<ClassType> *new_comparison(RetType (ClassType::*memberf)(void),
> RetType v){
>                   ^~~~~~~~~~~~~~
> etree.cc:82:18: note:   template argument deduction/substitution failed:
> etree.cc:87:73: note:   types 'RetType (c_nntp_file::)()' and 'long unsigned
> int (c_nntp_file::)() const' have incompatible cv-qualifiers
>   if      (opstr.compare("==")==0) return
> new_comparison<Op_eq,ClassType>(get, v);
>
> etc.
>
>
> I am not a C++ programmer but AIUI it is failing to find the specific
> function to execute in the template overload because of disagreements over
> typing (function return value vs a scalar, const vs non-cost etc.) and for
> that reason what would otherwise be a warning becomes a fatal error.  Is
> this correct?
>
> I was hoping one of the -std switches would revert the back to the GCC 4.2.0
> behaviour and allow me to do the build but none of the -std switches I tried
> made any difference.
>
> The etree.{h,cc} files and full (colourised) error report is at
> http://www.mklab.rhul.ac.uk/~tom/tmpetree.zip.
>
> Any thoughts?


The code is not valid C++. Presumably GCC 4.2 failed to diagnose it,
but that's not something you can change with -std switches. It's
simply invalid in all versions of C++.

The code tries to call new_comparison with  a member function pointer
of type 'long unsigned int (c_nntp_file::*&)() const' (which is a
pointer to a const member function).

There are two overloads of new_comparison, one takes a pointer to
data-member, and one takes a pointer to non-const member function.
That means neither overload is viable.

You should be able to fix the code by adding this to etree.cpp

template <template <class A, class B> class Op, class ClassType, class RetType>
pred<ClassType> *new_comparison(RetType (ClassType::*memberf)(void)
const, RetType v){
    return new Comparison<Op, MemfuncGetter, RetType, ClassType>(memberf, v);
}

This adds a third overload that takes a pointer to const member function.

You might be able to simply add "const" to the existing second
overload, which would let line 87 compile, but it would fail if there
are other calls that really do need to use non-const member functions.
Adding a third overload should work, whether or not the second one is
really needed.



[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