Problem with std::endl, left-shift operator and valarray

Sébastien Aubry sebastien.aubry31@gmail.com
Wed Dec 21 16:27:00 GMT 2016


Hi,

I cannot compile the following (reduced) code under CentOS 7.2 using
GCC 4.8.1, 4.8.5, 4.9.2, 5.2.0 (but it works with GCC 4.4.7).
It works fine under Linux Mint 18.1 with GCC 4.9.3 or 5.4.0.

The problem appears when I add the #include <valarray> statement,
despite not being used inside the code. The compiler tries to
instantiate std::valarray<Logger>.


Thanks

Regards

Sébastien Aubry



#include <iostream>
#include <valarray>

class Logger {
    public:
    Logger& operator<<(std::ostream& (*pf)(std::ostream&));

    private :
    virtual void write() = 0;
};

void test() {
    Logger *logger = NULL;
    *logger << std::endl;
}



$ g++ -v
[...]
gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)


$ g++ test.cpp
In file included from test.cpp:2:0:
/usr/include/c++/4.8.2/valarray: In instantiation of ‘class
std::valarray<Logger>’:
test.cpp:14:21:   required from here
/usr/include/c++/4.8.2/valarray:926:5: erreur: cannot allocate an
object of abstract type ‘Logger’
     valarray<_Tp>::sum() const
     ^
test.cpp:4:7: note:   because the following virtual functions are pure
within ‘Logger’:
 class Logger {
       ^
test.cpp:9:18: note:     virtual void Logger::write()
     virtual void write() = 0;



More information about the Gcc-help mailing list