Menu

False Positive, syntax Error

2020-08-07
2021-01-25
  • Raphael Baier

    Raphael Baier - 2020-08-07

    Minimal example:

    #include <type_traits>
    
    template<typename derived_type, typename base_type>
    using inherits_from = typename std::enable_if<
        std::is_base_of<base_type, derived_type>::value, int>::type;
    
    
    template <class T>
    struct Foo {};
    
    struct Bar : Foo<Bar> {};
    
    template <typename T, inherits_from<T,Foo<T>> = 0>
    void baz(T t){}
    
    int main()
    {
        baz(Bar{});
    }
    

    generates:

    ../source.cpp:15:1: error: syntax error [syntaxError]
    template <typename T,inherits_from<T,Foo<T>> = 0>
    ^
    

    but the code compiles just fine, the thing that seems to hickup here is the Foo<T> inside the inherits_from
    it also seems that only versions above 1.82 are affected
    when not using Foo<T> or when the code is changed to

    template <typename T, typename = inherits_from<T,Foo<T>>>
    

    the error does not occur

     
  • CHR

    CHR - 2021-01-25

    This does not reproduce with v2.3.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.