[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2024-03-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|NEW |RESOLVED

--- Comment #8 from Andrew Pinski  ---
Dup, and fixed already.

*** This bug has been marked as a duplicate of bug 78940 ***

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2019-10-09 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

--- Comment #7 from Jonathan Wakely  ---
As I noted at https://gcc.gnu.org/ml/gcc-help/2019-10/msg00038.html the guard
variable is emitted, but appears to be unused when compiled with
-fno-threadsafe-statics.

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2019-10-08 Thread klaus.doldinger64 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

--- Comment #6 from Wilhelm M  ---
This is still true for local statics as shown below:


// Test für guard variable 

struct A {
inline A(int v = 0) {} // without user-defined ctors, guards are omitted
int m1() const {
return m;
}
private:
int m = 0;
};

//namespace { // without anon-ns guards, are generated 
template
struct X {
static int foo() {
static T m; // even as local-static and -fno-threadsafe-statics,
guards are generated  
return m.m1();
}
//inline static T m;  
};
//}

int main() {
return X::foo();
}

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2018-01-08 Thread klaus.doldinger64 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

--- Comment #5 from Wilhelm M  ---
Only for completeness: if you write the following, no guards are produced:

struct A {
A() = default; // if commented out, no guards are allocated
void foo() {}
};

template
struct B {
static void foo() {
mTop.foo();
}
inline static T mTop{};
};

int main() {
B::foo();
}

So the c++14 an c++17 variants produce the same guards if
default-initialization is used. But produce no guards if value-initialization
ist used or the defaulted ctor is removed. Thats strange ...

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2018-01-08 Thread klaus.doldinger64 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

Wilhelm M  changed:

   What|Removed |Added

   Keywords|wrong-code  |

--- Comment #4 from Wilhelm M  ---
If you change the example as below, you still get guards.

struct A {
A() = default;
void foo() {}
};

template
struct B {
static void foo() {
mTop.foo();
}
static T mTop;
};

template T B::mTop; // change

int main() {
B::foo();
}

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2018-01-08 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||wrong-code
 Target|avr |
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-01-08
 Ever confirmed|0   |1

--- Comment #3 from Jonathan Wakely  ---
This happens on all targets, but only for a C++17 inline static member
variable.

There's no guard variable for the C++14 equivalent:

struct A {
A() = default;
void foo() {}
};

template
struct B {
static void foo() {
mTop.foo();
}
static T mTop;
};

template T B::mTop{};

int main() {
B::foo();
}

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2018-01-07 Thread klaus.doldinger64 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

--- Comment #2 from Wilhelm M  ---
Additionally: if one only uses a global variable of type A, no guards are
creates at all. But this should be conceptually equivalent to the above use
case.

[Bug c++/83730] Unnecessary generation of guard variables with -fno-threadsafe-statics

2018-01-07 Thread klaus.doldinger64 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83730

--- Comment #1 from Wilhelm M  ---
If the defaulted ctor is commented out, the guards aren't generated. Still is
even stranger ...