test.cpp [c++]

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
27
28
class Foo1
{
    public:
        const int* bar;

        Foo1()
        {
            bar = new int[2] {1, 2};
        }
};

template<int A, int B>
class Foo2
{
    public:
        const int* bar;

        Foo2()
        {
            bar = new int[2] {A, B};
        }
};

int main() {
   Foo1 a;
   Foo2<1,2> b;
}

Compiler output (plain_text)

1
2
3
4
5
6
7
$ gcc-4.7 -std=c++11 -o test test.cpp
test.cpp: In instantiation of ‘Foo2<A, B>::Foo2() [with int A = 1; int B = 2]’:
test.cpp:27:14:   required from here
test.cpp:21:13: error: parenthesized initializer in array new [-fpermissive]
test.cpp:21: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/ccjZKw1q.out file, please attach this to your bugreport.

/tmp/ccjZKw1q.out [c++]

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
27
28
29
30
31
32
33
// /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -quiet -imultiarch x86_64-linux-gnu -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -std=c++11 -o - -frandom-seed=0
# 1 "test.cpp"
# 1 "<command-line>"
# 1 "test.cpp"

class Foo1
{
    public:
        const int* bar;

        Foo1()
        {
            bar = new int[2] {1, 2};
        }
};

template<int A, int B>
class Foo2
{
    public:
        const int* bar;

        Foo2()
        {
            bar = new int[2] {A, B};
        }
};

int main() {
   Foo1 a;
   Foo2<1,2> b;
}