[cfe-dev] [C++11][initializer list]problem about direct-list-initialization to a function pointer

ZhangXiongpang zhangxiongpang at gmail.com
Tue Mar 19 19:57:16 PDT 2013


Platform: linux, x86_64, clang 3.2

I met a strange question when testing "initializer list" with clang++.
It reported error at direct-list-initialization to a function pointer in a
block scope.
At the beginning, I guessed clang++ parse it as a function defination.
Later I found it no longer reported error when I move the
direct-list-initialization sentence into global scope.

Test code is as follows:
------------------------------------------
struct X {
    void foo() {}
};

// global scope
void (*pf1)() {}; // ok
void (X::*pmf1)() {&X::foo}; // ok
void (X::*pmf2)() = {&X::foo}; // ok

// block scope
void test() {
    void (*pf2)() {}; // error
    void (X::*pmf3)() {&X::foo}; // error
    void (X::*pmf4)() = {&X::foo}; // ok
}
------------------------------------------



--
View this message in context: http://clang-developers.42468.n3.nabble.com/C-11-initializer-list-problem-about-direct-list-initialization-to-a-function-pointer-tp4031054.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list