Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build fails for clang with -Werror #1521

Closed
leissa opened this issue Mar 28, 2018 · 6 comments
Closed

build fails for clang with -Werror #1521

leissa opened this issue Mar 28, 2018 · 6 comments

Comments

@leissa
Copy link
Contributor

leissa commented Mar 28, 2018

error: missing field 'owner_' initializer [-Werror,-Wmissing-field-initializers]
GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
           ^
/home/roland/projects/thorin2/build_clang/googletest-src/googletest/include/gtest/internal/gtest-port.h:2102:80: note: expanded from macro 'GTEST_DEFINE_STATIC_MUTEX_'
     ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }

This regression must be introduced by one quite recent commit.

clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Same error using clang 5.0.0.

Removing -Werror fixes the build. However, I'd like to compile my projects with

-Wall -Wextra -Werror
@leissa leissa changed the title build fails for clang build fails for clang with -Werror Mar 28, 2018
@leissa
Copy link
Contributor Author

leissa commented Mar 28, 2018

include/gtest/internal/gtest-port.h:

// Defines and statically (i.e. at link time) initializes a static mutex.
// The initialization list here does not explicitly initialize each field,
// instead relying on default initialization for the unspecified fields. In
// particular, the owner_ field (a pthread_t) is not explicitly initialized.
// This allows initialization to work whether pthread_t is a scalar or struct.
// The flag -Wmissing-field-initializers must not be specified for this to work.
#  define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
     ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }

I don't get the comment. What's wrong with adding phthread_t()? It also works in the case that pthread_t is a scalar. Doing something like int() is just fine.

leissa added a commit to leissa/googletest that referenced this issue Mar 28, 2018
use default constructor of pthread_t in order to initialize mutex
patrick96 added a commit to patrick96/polybar that referenced this issue Apr 8, 2018
Compiling gtest with clang fails with -Wmissing-field-initializers as
reported in [1]
[1]: google/googletest#1521
patrick96 added a commit to polybar/polybar that referenced this issue Apr 9, 2018
Compiling gtest with clang fails with -Wmissing-field-initializers as
reported in [1]
[1]: google/googletest#1521
patrick96 added a commit to patrick96/polybar that referenced this issue Apr 9, 2018
Compiling gtest with clang fails with -Wmissing-field-initializers as
reported in [1]
[1]: google/googletest#1521
@henryiii
Copy link
Contributor

A fix was added in #633 (which I think is in 1.8.0), but somehow the current master seems to be missing this patch, causing a warning (or in the above case, error) again.

@chadbrewbaker
Copy link

Master still isn't fixed. Made the change here and it worked:

https://github.com/google/googletest/pull/633/files#diff-f21e2c91878df000cc7b8b316a89565c

lbonn added a commit to advancedtelematic/aktualizr that referenced this issue Jul 6, 2018
We stumbled on this: google/googletest#1521

So let's switch back to an older version of googletest, more
specifically, one commit before:

google/googletest@87a4cdd
dschlaep added a commit to DrylandEcology/SOILWAT2 that referenced this issue Jul 9, 2018
…tain setups

- address issue #206:
```
In file included from googletest/googletest/src/gtest-all.cc:42:
googletest/googletest/src/gtest.cc:393:12: error: missing field 'owner_' initializer [-Werror,-Wmissing-field-initializers]
GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
```
- this appears to be a problem described here google/googletest#1521 which remains unsolved as of today

- another project on github addressed this issue temporarily (advancedtelematic/aktualizr#841) by checking out `googletest` one commit before this problem was introduced with commit google/googletest@87a4cdd, i.e, google/googletest@7888184
@gennadiycivil
Copy link
Contributor

#1646 addressed that slightly differently

@gennadiycivil
Copy link
Contributor

@leissa is this still an issue?

@leissa
Copy link
Contributor Author

leissa commented Oct 7, 2018

Works for me now. Thanks :)

@leissa leissa closed this as completed Oct 7, 2018
cclauss added a commit to cclauss/googletest that referenced this issue Dec 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants