Skip to content

Misc warnings - #2801

Merged
vitaut merged 2 commits into
fmtlib:masterfrom
seanm:misc-warnings
Mar 24, 2022
Merged

vitaut merged 2 commits into
fmtlib:masterfrom
seanm:misc-warnings

Conversation

@seanm

@seanm seanm commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Comment thread include/fmt/compile.h Outdated
using pointer = void;
using reference = void;
using _Unchecked_type =
using Unchecked_type_ =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will introduce warnings in MSVC, please revert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What warning would it introduce?

Underscore followed by uppercase is reserved in C++: https://en.cppreference.com/w/cpp/language/identifiers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnings about (un)checked iterators.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _Unchecked_type some kind of Microsoft extension keyword?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of. It's not a keyword but some mechanism to opt out iterators.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we somewhere do something like:

#if defined(_MSC_VER)
  #define fmt_unchecked_type _Unchecked_type
#else
  #define fmt_unchecked_type
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have access to MSVC 2015, I'd recommend checking if removing _Unchecked_type altogether still produces warnings. It might be no longer the case as IIRC they have been moving away from the checked iterators. You could even submit a test PR to the fmt repo and check warnings in appveyor: https://ci.appveyor.com/project/vitaut/fmt.

@vitaut vitaut Mar 8, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we can see on this PR that there are definitely more warnings: https://ci.appveyor.com/project/vitaut/fmt/builds/42816914/job/briwktqjiiw9oa34. The macro approach seems OK but note that macros should be uppercase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, see new attempt.

Comment thread include/fmt/core.h Outdated
using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
appender(base it) noexcept : base(it) {}
using _Unchecked_type = appender; // Mark iterator as checked.
using Unchecked_type_ = appender; // Mark iterator as checked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment thread test/test-main.cc
Comment thread include/fmt/compile.h Outdated
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_

#include "core.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed: core.h is a lightweight alternative to format.h, it doesn't make sense to include it when format.h is included.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread include/fmt/core.h
Comment on lines +220 to +225
#ifdef _MSC_VER
# define FMT_UNCHECKED_TYPE _Unchecked_type
#else
# define FMT_UNCHECKED_TYPE DummyName
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change it into:

#define FMT_UNCHECKED_ITERATOR(It) using _Unchecked_type = It; // Mark iterator as checked.

to simplify call sites.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread include/fmt/core.h Outdated
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.
namespace align {
enum type { none, left, right, center, numeric };
enum type : unsigned { none, left, right, center, numeric };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why unsigned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per commit message: to fix the -Wsigned-enum-bitfield warnings.

Comment thread test/posix-mock-test.cc
Comment thread include/fmt/compile.h Outdated
Comment on lines 39 to 40
using FMT_UNCHECKED_TYPE =
truncating_iterator_base; // Mark iterator as checked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be `FMT_UNCHECKED_TYPE(truncating_iterator_base);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, sorry I missed that one. Fixed.

Comment thread include/fmt/core.h Outdated
Comment on lines +221 to +223
# define FMT_UNCHECKED_ITERATOR(It) using _Unchecked_type = It; // Mark iterator as checked.
#else
# define FMT_UNCHECKED_ITERATOR(It) using DummyTypeName = It;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove trailing semicolons since those are added at call sites.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. Fixed.

Comment thread test/posix-mock-test.cc
@vitaut

vitaut commented Mar 11, 2022

Copy link
Copy Markdown
Contributor

Please fix build failures.

@vitaut

vitaut commented Mar 11, 2022

Copy link
Copy Markdown
Contributor

And apply clang-format.

@seanm

seanm commented Mar 15, 2022

Copy link
Copy Markdown
Contributor Author

Please fix build failures.

I don't understand that error. I played on godbolt, and it seems to me like a gcc bug fixed between 9.2 and 9.3:

https://godbolt.org/z/58aEv8zEq

Interesting, the warning goes away if I change the enum from unsigned to unsigned char. Shall we do that?

@vitaut

vitaut commented Mar 15, 2022

Copy link
Copy Markdown
Contributor

Interesting, the warning goes away if I change the enum from unsigned to unsigned char. Shall we do that?

If that resolves the issue then sure.

@vitaut

vitaut commented Mar 17, 2022

Copy link
Copy Markdown
Contributor

There are still build failures.

@vitaut

vitaut commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Do you still plan working on this PR?

@seanm

seanm commented Mar 24, 2022

Copy link
Copy Markdown
Contributor Author

Do you still plan working on this PR?

Yes. But I'm at a loss as to why that old gcc complains. I don't have a means to reproduce it locally.

I guess I could split that one commit out so the rest can be merged...

seanm added 2 commits March 24, 2022 09:57
Avoid defining various reserved identifiers (starting with underscore and capital letter).  Fortunately, they were all Windows-only, so it was easy to conditionalize them in Window-only preprocessor checks.
Created FMT_UNCHECKED_TYPE that resolves to special identifier _Unchecked_type for Microsoft, but to a dummy string otherwise. Using
_Unchecked_type is invalid because underscore + uppercase is a reserved identifier.
@vitaut
vitaut merged commit 5379063 into fmtlib:master Mar 24, 2022
@vitaut

vitaut commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Thanks

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

Successfully merging this pull request may close these issues.

3 participants