language: C++ 4.7.2 (gcc-4.7.2)
date: 1096 days 1 hour ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <vector>
#include <string>
#include <iostream>
 
template<typename T>
void foo(T x) {
    std::vector<decltype(x.bar())> v;
    v.push_back(x.bar());
    v.push_back(x.bar());
    v.push_back(x.bar());
    std::cout << v.size() << std::endl;
}
 
class MyClass {
public:
        std::string bar() {
                std::cout << "MyClass.bar is called" << std::endl;
                return "abc";
        }
};
 
int main() {
        MyClass obj;
        foo(obj);
}
 
prog.cpp: In function ‘void foo(T)’:
prog.cpp:7: error: `.' cannot appear in a constant-expression
prog.cpp:7: error: a function call cannot appear in a constant-expression
prog.cpp:7: error: a function call cannot appear in a constant-expression
prog.cpp:7: error: template argument 1 is invalid
prog.cpp:7: error: template argument 2 is invalid
prog.cpp:7: error: invalid type in declaration before ‘;’ token
prog.cpp:8: error: request for member ‘push_back’ in ‘v’, which is of non-class type ‘int’
prog.cpp:9: error: request for member ‘push_back’ in ‘v’, which is of non-class type ‘int’
prog.cpp:10: error: request for member ‘push_back’ in ‘v’, which is of non-class type ‘int’
prog.cpp:11: error: request for member ‘size’ in ‘v’, which is of non-class type ‘int’