Skip to content

initializing static variables #369

@fekir

Description

@fekir

Since c++11, static variables are initialized thread-safely once in case of success.

cppinsights shows this correctly for

struct foo{foo();};

const foo& create(){
	static foo value = foo(); // exception handling is there
  	return value;
}

(ie and catch(...) with __cxa_guard_abort is present)

but does not for those variants (adding const or an indirection through a lambda or function)

struct foo{foo();};

const foo& create(){
  	static const foo value = foo(); // exception handling missing
  	return value;
}
struct foo{foo();};

const foo& create(){
  	static foo value = [](){return foo();}(); // exception handling missing
  	return value;
}
struct foo{foo();};

foo make_foo(){
	return foo();
}

const foo& create(){
	static foo value = make_foo(); // exception handling missing
  	return value;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions