Thread: clang++ works but g++ doesn't -- Maybe a compiler bug?

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    China
    Posts
    74

    Exclamation clang++ works but g++ doesn't -- Maybe a compiler bug?

    clang++ can compile the following code without any error and warning, but g++ always gives me the error "no matching call ..."? Is it a bug of g++ or kind of extensions of clang++?
    Code:
    #include <algorithm> 
    
    int main() 
    { 
        struct utils 
        { 
            struct int_type 
            { 
                int m_value; 
            }; 
    
            static int_type& transform_predicate(int_type& x) 
            { 
                x.m_value += 1; 
                return x; 
            } 
        }; 
        static utils::int_type array[1048576]; 
        int i; 
    
        for(i = 0; i < 1048576; i++) 
            array[i].m_value = i; 
    
        std::transform(array, array + 1048576, array, utils::transform_predicate); 
        return 0; 
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Comeau reports several errors concerning "a template argument may not reference a local type".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Looks like you have one line out of place:
    Code:
    #include <algorithm> 
    
    struct utils 
        { 
            struct int_type 
            { 
                int m_value; 
            }; 
    
            static int_type& transform_predicate(int_type& x) 
            { 
                x.m_value += 1; 
                return x; 
            } 
        }; 
    
    int main() 
    { 
        
         utils::int_type array[1048576]; 
        int i; 
    
        for(i = 0; i < 1048576; i++) 
            array[i].m_value = i; 
    
        std::transform(array, array + 1048576, array, utils::transform_predicate); 
        return 0; 
    }
    works fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesn't it works?
    By curious in forum C Programming
    Replies: 21
    Last Post: 05-24-2008, 06:04 PM
  2. Why This doesn't work and the other one works?
    By chottachatri in forum C++ Programming
    Replies: 21
    Last Post: 03-26-2008, 08:01 AM
  3. Why <complete program> doesn't works right?
    By Gamer_Jimbo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2006, 02:28 AM
  4. 'GetConsoleWindow' doesn't works ??!
    By andre123 in forum Windows Programming
    Replies: 11
    Last Post: 09-10-2003, 11:45 PM
  5. Works on Dev C++, Doesn't on Visual C++ :(
    By marcvb in forum C++ Programming
    Replies: 6
    Last Post: 11-26-2001, 08:39 AM