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



             Bug #: 54905

           Summary: invalid use of qualified-name 'std::cout'

    Classification: Unclassified

           Product: gcc

           Version: 4.6.4

            Status: UNCONFIRMED

          Severity: blocker

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: ace.of.zeros...@gmail.com





The code below builds fine with any version of GCC 4.x



########

#include <iostream>



void Test(std::ostream &stream) {

        stream << "Hello, World!" << std::endl;

}



int main() {

        Test(std::cout);

        return 0;

}

########



But

GCC 4.2.1, 4.4.0, 4.6.4 and 4.7.3 refuse to build the below code while VC++10,

VC++11 and both CLANG 3.0 and 3.1 are building it without any issue or warning.



[ I got it from here:

http://stackoverflow.com/questions/8629382/debug-macro-for-c-with-variable-arguments-without-the-format-string

]



########

#include <iostream>

#include <string>



class VariadicToOutputStream

{

public:

    VariadicToOutputStream(std::ostream& s, const std::string& separator = " ")

: m_stream(s), m_hasEntries(false), m_separator(separator) {}

    template<typename ObjectType>

    VariadicToOutputStream& operator , (const ObjectType& v)

    {

        if (m_hasEntries) m_stream << m_separator;

        m_stream << v;

        m_hasEntries=true;

        return *this;

    }

    ~VariadicToOutputStream()

    {

        m_stream << std::endl;

    }



private:

    std::ostream& m_stream;

    bool m_hasEntries;

    std::string m_separator;

};



#define VARIADIC_TO_STDOUT(...)    \

    VariadicToOutputStream(std::cout),__VA_ARGS__;



int main() {

    VARIADIC_TO_STDOUT(1, 0.5f, "a string");

    return 0;

}

########





The error produced by GCC:

########

main.cpp: In function 'int main()':

main.cpp:31:2: error: invalid use of qualified-name 'std::cout'

main.cpp:31:2: error: expected unqualified-id before numeric constant

########





Versions of GCC that I've used:

g++ (GCC) 4.2.1 20070831 patched [FreeBSD]

g++46 (FreeBSD Ports Collection) 4.6.4 20120928 (prerelease)

g++47 (FreeBSD Ports Collection) 4.7.3 20120929 (prerelease)

MinGW g++ (GCC) 4.4.0

Reply via email to