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

This is a discussion on clang++ works but g++ doesn't -- Maybe a compiler bug? within the C++ Programming forums, part of the General Programming Boards category; clang++ can compile the following code without any error and warning, but g++ always gives me the error "no matching ...

  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
    22,302
    Comeau reports several errors concerning "a template argument may not reference a local type".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,185
    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, 07: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, 09: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-11-2003, 12:45 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21