Indiana Unversity logo[ConceptGCC]

ConceptGCC :

ConceptGCC: Confusing behaviour

From: Daniel Lincke (daniel.lincke_at_[hidden])
Date: 2007-09-30 10:52:50


Hi ConceptGCC-users,

I'm still exploring ConceptGCC, and I got some behaviour which I do not
understand. Here's the code:

=======================================================================

#ifdef __GXX_CONCEPTS__
concept HasValueType<class C> {
    typename value_type;
};
#endif

template<class C>
class MyMapType : public map<C, double> {
};

template <typename T>
#ifdef __GXX_CONCEPTS__
// Requirements for myStruct1
//requires
// HasValueType<T>
#endif
struct myStruct1 {
    typedef MyMapType<typename T::value_type> value_type; // Line 37

    void foo(value_type const& x) const { // Line 39
        // define iterator it
        //typename value_type::const_iterator it=x.begin();
    }
};

template <typename T>
#ifdef __GXX_CONCEPTS__
// Requirements for myStruct2
//requires
// HasValueType<T>requires
#endif
struct myStruct2 {

    typedef typename myStruct1<T>::value_type value_type; // Line 57

    void foo(value_type const& x) {
        myStruct1<T> temp; // Line 60
        value_type v;
        temp.foo(v); // Line 62
    }
};

struct XX {
    typedef int value_type;
};

#ifdef __GXX_CONCEPTS__
concept_map HasValueType<XX> {
    typedef XX::value_type value_type;
}
#endif

int main (int argc, char *argv[]) {

    MyMapType<int> x;
    myStruct1<XX> f;

    f.foo(x);

}

================================================================

It compiles successfully in the form it is shown above.

If I activate the requirements for both structs, it also works fine

If I activate the requirements for myStruct2 and deactivate the ones for
myStruct1 compilation fails:
main.cpp: In instantiation of ‘myStruct1<T>’:
main.cpp:57: instantiated from here
main.cpp:37: error: no type named ‘value_type’ in ‘struct T’
main.cpp:39: error: no type named ‘value_type’ in ‘struct T’
main.cpp:57: error: invalid combination of multiple type-specifiers
main.cpp: In instantiation of ‘myStruct1<T>’:
main.cpp:60: instantiated from here
main.cpp:37: error: no type named ‘value_type’ in ‘struct T’
main.cpp:39: error: no type named ‘value_type’ in ‘struct T’
main.cpp: In member function ‘void myStruct2<T>::foo(const int&)’:
main.cpp:62: error: ‘struct myStruct1<T>’ has no member named ‘foo’

If I activate both requirements and the Iterator def. in line 41
compilation also fails:
/opt/conceptgcc-4.3/bin/conceptg++ -include bits/stdc++.h -c -o
main.o main.cpp
main.cpp: In member function ‘void myStruct1<T>::foo(const
MyMapType<HasValueType<T>::value_type>&) const [with T = XX]’:
main.cpp:84: instantiated from here
main.cpp:41: error: ‘std::map<value_type, double, std::less<value_type>,
std::allocator<std::pair<const value_type, double> > >::begin’ is not a
member of ‘const MyMapType<int>’
make: *** [main.o] Fehler 1

If I deactivate the requirements but activate the Iterator def. it works
fine.

:confused: ... seems to be confusing for me ... can someone explain this
behavoir? Is it wanted or some kind of bug?

Greetings and thanks,
dl