Skip to content

Conversation

@autoantwort
Copy link
Contributor

@autoantwort autoantwort commented Jun 11, 2025

These defines are set by msbuild if CharacterSet is set to Unicode.

TestCppCheckProject.zip
This test project compiles fine but the current cppcheck version reports:

$ cppcheck --project=TestCppCheckProject.sln --project-configuration="Debug|Win32"
Checking main.cpp Debug|Win32...
main.cpp:7:0: error: #error "nicht definiert" [preprocessorErrorDirective]
#error "nicht definiert"
^

with this PR

$ cppcheck --project=TestCppCheckProject.sln --project-configuration="Debug|Win32"...
Checking main.cpp Debug|Win32...
Checking main.cpp: _WIN32=1;WIN32=1;_DEBUG=1;_CONSOLE=1;__SSE2__=1;UNICODE=1;_UNICODE=1;_MSC_VER=1900...
main.cpp

#include <iostream>

#ifndef _UNICODE
#error "nicht definiert"
#endif

#ifndef UNICODE
#error "Not supported"
#endif // UNICODE


int main()
{

        std::cout << "Hello World!\n";
}

… Unicode

These defines are set by msbuild if CharacterSet is set to Unicode
@firewave
Copy link
Collaborator

This should also get a ticket as well as Python tests.

On a side note IIRC the current UNICODE handling is a bit of a mess. I need to look at the status quo and see if I filed tickets for all known shortcomings (it might even require simplecpp changes). So beware of rabbitholes.

@danmar
Copy link
Owner

danmar commented Jun 12, 2025

This should also get a ticket as well as Python tests.

I am not sure why a python test would be needed.. I would be fine with a test in testimportproject.cpp

but a ticket would be nice. Do you have a trac account? Should I create this ticket?

@firewave
Copy link
Collaborator

I am not sure why a python test would be needed.. I would be fine with a test in testimportproject.cpp

Because it requires a project which contains sources which depend on that define. Generating files in the unit tests should be avoided. And it would be much easier to do in the Python tests.

@danmar
Copy link
Owner

danmar commented Jun 12, 2025

Because it requires a project which contains sources which depend on that define. Generating files in the unit tests should be avoided. And it would be much easier to do in the Python tests.

imho it does not require any physical files.

We can write a TestImportProject test that contains a minimal vcxproj xmldata.

     void testVcxprojUnicode() {
         const char vcxproj[] = "...";
         tinyxml2::XMLDocument doc;
         ASSERT_EQUALS(tinyxml2::XML_SUCCESS, doc.Parse(vcxproj, sizeof(vcxproj)));
         TestImporter project;
         project.importVcxproj(doc, ...);
         ASSERT_EQUALS(check that there are proper UNICODE defines);
     }

@autoantwort
Copy link
Contributor Author

Ok I can write a testVcxprojUnicode. I only have to change that importVcxproj accepts a XMLDocument and is protected and not private.

@firewave
Copy link
Collaborator

Ok I can write a testVcxprojUnicode. I only have to change that importVcxproj accepts a XMLDocument and is protected and not private.

You can just make the test fixture it a friend for now. We do that all over the place now and that needs a better approach - until then we should be consistent.

@autoantwort
Copy link
Contributor Author

While writing tests I realized that one could set different UseOfMfc and CharacterSet values based on the configuration, so I fixed that and added tests :)

@autoantwort autoantwort force-pushed the msbuild-define-UNICODE-if-CharacterSet-is-Unicode branch from 9a3e9e7 to 7d6ef56 Compare June 12, 2025 18:55
@firewave
Copy link
Collaborator

While writing tests I realized that one could set different UseOfMfc and CharacterSet values based on the configuration, so I fixed that and added tests :)

Not going into how that should go away. Something for later.

I now remember what is flawed here and why I wanted a Python test. It is the handling of the *A/*W functions. That should not be adjusted in the scope of this PR. Like stated before I will check if tickets for these things exist.

And I also mixed up the (implicit) _UNICODE defines with the (explicit) {_}WIN* defines.

@firewave
Copy link
Collaborator

I think https://trac.cppcheck.net/ticket/13251 and https://trac.cppcheck.net/ticket/13262 are mostly covering this.

@autoantwort
Copy link
Contributor Author

Ok. So when this is something for later this MR is complete? (From my side it is)

@danmar
Copy link
Owner

danmar commented Jun 13, 2025

a ticket for this PR is still missing right? The PR title should point at the ticket. If you would create a htpasswd hash and send it to me I will make sure that you will get a trac account.

@autoantwort autoantwort changed the title VisualStudio Importer: Define UNICODE=1;_UNICODE=1 if CharacterSet is Unicode Fixes #13956: VisualStudio Importer: Define UNICODE=1;_UNICODE=1 if CharacterSet is Unicode Jun 20, 2025
@danmar danmar merged commit d95ae44 into danmar:main Jun 22, 2025
53 checks passed
@danmar
Copy link
Owner

danmar commented Jun 22, 2025

@autoantwort as far as I see you have not been added to the AUTHORS file. what name do you want that I add there?

@autoantwort autoantwort deleted the msbuild-define-UNICODE-if-CharacterSet-is-Unicode branch June 22, 2025 15:43
@autoantwort
Copy link
Contributor Author

@autoantwort as far as I see you have not been added to the AUTHORS file. what name do you want that I add there?

You can add Leander Schulten

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