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

MSVC: BOOST_PP_STRINGIZE __LINE__ #39

Open
ohhmm opened this issue Aug 17, 2021 · 20 comments
Open

MSVC: BOOST_PP_STRINGIZE __LINE__ #39

ohhmm opened this issue Aug 17, 2021 · 20 comments

Comments

@ohhmm
Copy link

ohhmm commented Aug 17, 2021

Broken on MSVC:

BOOST_PP_STRINGIZE(__LINE__) returns "__LINE__"

@eldiener
Copy link
Collaborator

eldiener commented Aug 17, 2021

I am not seeing this in VS2019 with the latest Boost. What version of MSVC are you using and what version of Boost are you using ? My test program is:

# include <iostream>
# include <boost/preprocessor/stringize.hpp>

int main() 
	{
	std::cout << '\n' << BOOST_PP_STRINGIZE(__LINE__) << '\n';
        return 0;
        }

and the output is 6 and not "__LINE__".

@ohhmm
Copy link
Author

ohhmm commented Aug 18, 2021

Visual Studio 2022 community preview version 17.0.0 Preview 3.
Boost 1.76 installed to C:\Boost

@eldiener
Copy link
Collaborator

eldiener commented Aug 18, 2021

Can you try Visual Studio 2019 or Visual Studio 2019 Preview and see if you get the same results as with Visual Studio 2022 Preview ? I tried Visual Studio 2019 or Visual Studio 2019 Preview and I got the correct result. I really, really doubt that this is a Boost PP problem. Nothing in the BOOST_PP_STRINGIZE code has changed that would suggest a bug in Boost PP. If you can give me a command line with the compiler options you use it would be appreciated. I have downloaded Visual Studio 2022 Preview and will try it once I get it setup to use with Boost on my local machine.

@ohhmm
Copy link
Author

ohhmm commented Aug 18, 2021

Here is where it used https://github.com/ohhmm/openmind/blob/703e42a40122f82ee7d8061fedd53b6740751e20/omnn/math/Valuable.h#L24
If anything needed, surely I'll try to help.

@eldiener
Copy link
Collaborator

Did you try my simple example above and see if the result matches mine ?

@ohhmm
Copy link
Author

ohhmm commented Aug 18, 2021

It was ok with 2019

@eldiener
Copy link
Collaborator

eldiener commented Aug 18, 2021

Then it must be something with the new preview since it was also OK with the 2019 preview. If my simple example failed with 2022 preview and succeeds with VS2019, then you might want to report it as a bug to Microsoft. You can lift the code from the stringize.hpp header file in your report and massage it if you like, but it is really very simple. BOOST_PP_CONFIG_MSVC() in stringize.hpp is turned on for VC++ using the default preprocessor but is not set when the new preprocessor is being used. Either way, whether with the default preprocessor or the new preprocessor my tests showed that the correct result occurred with both VS2019 and VS2019 Preview. I would imagine that in the 2022 preview that the new preprocessor might now be the default but even in that case the code in stringize.hpp should work fine even if the code for the old, default preprocessor is being used, which I doubt is actually the case.

@eldiener
Copy link
Collaborator

I was able to setup VS2022 Preview and tried my code above with both the default preprocessor and the new preprocessor and the result was correctly "6" and not "__LINE__".

@ohhmm
Copy link
Author

ohhmm commented Aug 19, 2021

I had this case: __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__) " "

@eldiener
Copy link
Collaborator

I changed the program I used to test, called test_stringize.cpp, to:

# include <iostream>
# include <boost/preprocessor/stringize.hpp>

int main() 
    {
    std::cout << '\n' << __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__) " " << '\n';
    return 0;
    }

and in all cases the correct result of test_stringize.cpp:6 was printed. This same correct result occured with msvc-14.2 msvc-14.2 preview and msvc-14.3 preview, whether I was using the default preprocessor or the new preprocessor. Would you please try the above program yourself ?

@ohhmm
Copy link
Author

ohhmm commented Aug 19, 2021

Sure, will do.

@ohhmm
Copy link
Author

ohhmm commented Aug 20, 2021

Reproduced in VS2022 Test Explorer window.
This workaround works:
image

@eldiener
Copy link
Collaborator

I can not read your image. Please copy as code if you want me to read it.

@eldiener
Copy link
Collaborator

I am assuming the problem is in your code and not in this library. Can I close this issue ?

@ohhmm
Copy link
Author

ohhmm commented Aug 24, 2021

image

@ohhmm
Copy link
Author

ohhmm commented Aug 24, 2021

See the LINE in the message. The workaround patch diff shown working well through third level of macro indirection is here ohhmm/openmind@2a84c9d

@eldiener
Copy link
Collaborator

I can not follow what you are trying to show me. You need to produce a simple code example which shows a problem with BOOST_PP_STRINGIZE(__LINE__). That means not some image which it is impossible for me to follow.

@ohhmm
Copy link
Author

ohhmm commented Aug 25, 2021

Hi Edward,

It appears to be only reproduced inside the Visual Studio Test Console.
So the simple test must be a boost test launched through the Visual Studio Tests Console.
See the test output message on the screenshot, it contains __LINE__.
Feel free to use the project Modulo test to reproduce.
Simply adding one more macro indirection solves the problem.

Thanks & Regards
Serg

@andry81
Copy link

andry81 commented Aug 25, 2021

It appears to be only reproduced inside the Visual Studio Test Console.

Visual Studio Test Console is not a compiler. You have to reproduce the bug in a compiler.

@ohhmm
Copy link
Author

ohhmm commented Aug 25, 2021

Ok, I'll capture its params

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

3 participants