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

For cpp20, renaming tests for using for scoped enums #72

Closed

Conversation

celikelozdinc
Copy link

@celikelozdinc celikelozdinc commented Jan 22, 2024

Via this commit, I aimed to resolve the task using for scoped enums which is indicated on issue 58

@@ -20,7 +20,8 @@ void require_equal(char const *file, unsigned line, T expected, U actual)
if (expected != actual)
{
std::ostringstream message;
message << file << '(' << line << "): error: expected " << expected << ", got " << actual;
//message << file << '(' << line << "): error: expected " << expected << ", got " << actual;
Copy link
Author

Choose a reason for hiding this comment

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

Since I've build errors on Ubuntu 22.04.3 LTS with clion, needed to change thsese lines.

Choose a reason for hiding this comment

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

The correct fix is to provide a stream insertion operator for the scoped enum.

Choose a reason for hiding this comment

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

The only place where enum class is used is in RenameCpp11.cpp and in all cases the enum is cast to an int before calling require_equal

Copy link
Owner

@LegalizeAdulthood LegalizeAdulthood Jan 22, 2024

Choose a reason for hiding this comment

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

For your new tests cases to int or move the enum to a namespace scope where a stream insertion operator can be defined would be the right fix instead of changing the entire require_equal mechanism.

Copy link
Author

Choose a reason for hiding this comment

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

I confused about this comment, on master branch, when I build refactor-test-suite, I get the errors below which states the lines that I've never changed:

.../RefactorTest/Require.h:23:65: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup
message << file << '(' << line << "): error: expected " << expected << ", got " << actual;
^
.../RefactorTest/RenameCpp20.cpp:73:9: note: in instantiation of function template specialization 'require_equal<std::strong_ordering, std::strong_ordering>' requested here
REQUIRE_EQUAL(std::strong_ordering::equal, x <=> x);

Choose a reason for hiding this comment

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

Ah, OK... I thought I had added stream insertion operators for those... linux CI build is compiling without errors.

Choose a reason for hiding this comment

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

What version compiler are you using?

Choose a reason for hiding this comment

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

google says ubuntu 22.04.3 LTS is using gcc-11, but I can't reproduce your error on compiler explorer:
https://godbolt.org/z/36Y6vxeTn

Choose a reason for hiding this comment

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

Please revert this change.

Copy link
Owner

@LegalizeAdulthood LegalizeAdulthood left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Please update per my comments.

@@ -278,7 +278,7 @@ void f8()
{
// #TEST#: R937 Rename local variable vals
// #TEST#: R938 Rename use of one
const int vals[3](one, 2, 3);
const int vals[3]{one, 2, 3};

Choose a reason for hiding this comment

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

Don't change these. The comment on line 273 explicitly says that this is initialization via parentheses.

void f11()
{
//#TEST#: R1521 Rename E
enum class E : uint8_t {

Choose a reason for hiding this comment

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

clang-format all source code changes

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, clang-format is applied


struct F11 {
using enum E;
}f11Ins;

Choose a reason for hiding this comment

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

Separate declaration of struct and declaration of variable

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, separated

using enum E;
}f11Ins;

const auto& get_enumerator = [&]() -> auto {

Choose a reason for hiding this comment

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

Odd that you are taking a reference to a temporary. Not undefined behavior, but just odd.

@@ -2102,6 +2102,10 @@ R1517 |
R1518 |
R1519 |
R1520 |
R1521 |

Choose a reason for hiding this comment

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

You'll need to rebase on HEAD as I'm adding lots of tests recently. Easiest thing to do is to mark the tests as newly added and re-add them using the add-tests tool as described in Contributing.md

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, rebased.

void f11()
{
//#GOINK#: ID Rename E
enum class E : uint8_t

Choose a reason for hiding this comment

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

This fails to build when the enum is local to this function. I suspect that is because the anonymous class created for the lambda is emitted to the enclosing namespace scope and not as a local inside this function. If I move the enum to namespace scope, then it compiles. Please update your code to put the enum in the namespace scope to correct this build error.

Choose a reason for hiding this comment

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

Also you haven't included a header to define uint8_t and it's not important to this test, so just drop off the : uint8_t base type and declare enum class E

//#GOINK#: ID Rename E
enum class E : uint8_t
{
//#GOINK#: ID Rename One

Choose a reason for hiding this comment

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

Please put a space between the comment introducer (//) and the test marker

@@ -20,7 +20,8 @@ void require_equal(char const *file, unsigned line, T expected, U actual)
if (expected != actual)
{
std::ostringstream message;
message << file << '(' << line << "): error: expected " << expected << ", got " << actual;
//message << file << '(' << line << "): error: expected " << expected << ", got " << actual;

Choose a reason for hiding this comment

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

Please revert this change.

@LegalizeAdulthood
Copy link
Owner

I've corrected the problems and merged your (amended by me) commit to master.

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.

2 participants