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

Poco::format receives empty Vector<Any> #3683

Closed
KevDi opened this issue Jul 13, 2022 · 12 comments
Closed

Poco::format receives empty Vector<Any> #3683

KevDi opened this issue Jul 13, 2022 · 12 comments

Comments

@KevDi
Copy link
Contributor

KevDi commented Jul 13, 2022

Describe the bug
I have the strange behaviour that when i call Poco::format(std::string& result, const std::string& fmt, const std::vector<Any>& values) the function always receives an empty vector. This will then crash the Program because it tries to dereference an iterator to that vector.

To Reproduce
This is the Example which leads to the crash on my side:

#include <iostream>
#include <Poco/Any.h>
#include <vector>
#include <Poco/Format.h>


void dummy_func(const std::vector<Poco::Any>& para) {
  std::cout << para.size() << '\n';
}

int main()
{
  std::vector<Poco::Any> values;
  std::string dummy{ "3.3.2" };
  std::string result;
  std::string fmt{ "Dummy: %s" };
  values.emplace_back(dummy);
  dummy_func(values);
  Poco::format(result, fmt, values);
}

If i call a function which accepts a Reference to an std:vector<Poco::Any> the function receives the correct vector.
I'm not sure why it is not working in the Poco::format function.

Here you can see that the vector contains elements before calling Poco::format:

Image

and inside Poco::format:

Image2

Please add relevant environment information:

  • Windows 10
  • 1.12.0
@KevDi KevDi added the bug label Jul 13, 2022
@aleks-f
Copy link
Member

aleks-f commented Jul 13, 2022

Can't reproduce

image

@aleks-f aleks-f self-assigned this Jul 13, 2022
@aleks-f aleks-f removed the bug label Jul 13, 2022
@aleks-f
Copy link
Member

aleks-f commented Jul 13, 2022

@KevDi I recommend a thorough cleanup and check of your development environment - my best guess at this point is that you have some headers or binaries version mixup somewhere

@KevDi
Copy link
Contributor Author

KevDi commented Jul 13, 2022

ok yeah this could be possible because i just did a git pull to get the latest version of the master branch so maybe i check it out directly from git again to get a clean version of poco

@KevDi
Copy link
Contributor Author

KevDi commented Jul 13, 2022

@aleks-f I just did a clean build from poco. Same error. But i found out that if i add the /permissive- (Conformance Mode) Option i got again the Issues i mentioned (#3683 & #3682)

@KevDi
Copy link
Contributor Author

KevDi commented Jul 13, 2022

@aleks-f i did some further investigations on two different systems.
System 1:

  • Windows 10
  • Visual Studio 2019 Professional
  • Platform Toolset v142

System 2:

  • Windows 10
  • Visual Studio 2022 Professional
  • Platform Toolset v142 & v143

On both systems i did a clean checkout of the Poco Library and build them with the buildwin.cmd command. I built the standard CppUnit, Foundation, Encodings, Net, XML, JSON, Util, Prometheus components. On both systems with the option 160 build shared both x64 nosamples notests

On both systems i created a simple Console Application with the default settings from Visual Studio.
This was the code i added to both projects:

#include <iostream>
#include <Poco/Any.h>

int main() {
  Poco::Any any_type;
  std::cout << "Test\n";
}

Both of the Project had the Conformance Mode set to /permissive- (Conformance Mode enabled).
If i build both projects the compiling failed with the Message from Issue #3682.

If i set Conformance Mode to /permissive (Conformance Mode disabled) both projects did compile successfully.

I searched then about the option on the Windows Documentation (/permissive- (Standards conformance)

I looked also into what of the /Zc options are set if the /permissive- Option is given.

It seems like the Option which causes the Problem is the /Zc:twoPhase. With this option Windows uses two-phase name lookup.
If i disable this Option by adding /Zc:twoPhase- as an additional Option under Configuration Properties > C/C++ > Command Line the program compiles even with /permissive- .

Here is the Documentation of the /Zc:twoPhase Option: /Zc:twoPhase- (disable two-phase name lookup)

@aleks-f
Copy link
Member

aleks-f commented Jul 13, 2022

ah, it probably wants a typename or template somewhere in the assign function declaration. see if you can find where, or wait until I have time (and patience) to deal with that dumb compiler (other compilers seem to have no issues with it)

@KevDi
Copy link
Contributor Author

KevDi commented Jul 13, 2022

@aleks-f i stopped counting how often i was frustrated by Microsoft and it's interpretation of the C++ Standard.
If i have the time i will check the assign function tomorrow and see if i can fix that issue

@KevDi
Copy link
Contributor Author

KevDi commented Jul 14, 2022

@aleks-f i tried adding typename or template to the function declaration but with no luck. But it could be that there is a bug in the Compiler it self. I opened a ticket at the Microsoft Visual Studio Developer Community.

@aleks-f
Copy link
Member

aleks-f commented Jul 15, 2022

I'm starting to lean towards a compiler bug. If there is a corresponding define for the /Zc:twoPhase, then we can disable SOO for it as a workaround until MS compiler comes to its senses.

Btw, I'm not seeing /permissive- as a default on VS 2019 or 2022

@aleks-f
Copy link
Member

aleks-f commented Jul 15, 2022

An interesting observation: it will compile with both /Zc:twoPhase and /Zc:twoPhase-

Although it obviously has an effect, the explicitly enabled two-phase lookup is not recognized as a valid option:

cl : command line warning D9002: ignoring unknown option '/Zc:twoPhase'

@KevDi
Copy link
Contributor Author

KevDi commented Jul 15, 2022

@aleks-f according to the documentation it seems like there is only the /Zc:twoPhase- option to disable it. To enable it you have to set the /permissive- option. As far as i understand it from the documentation.
But yes i agree with you that it is more likely a bug in the Compiler.

@KevDi
Copy link
Contributor Author

KevDi commented Jul 20, 2022

@aleks-f It seems like Microsoft has approved this as a Bug according to my Request on the Developer Community.
They also provide a Workaround which should let the Code compile in /permissive mode.
Instead of using:

struct Size
{
	static const unsigned int value = SizeV;
};

an enum should be used:

struct Size
{
	enum { value = SizeV };
};

@aleks-f aleks-f added this to the Release 1.12.2 milestone Jul 25, 2022
aleks-f added a commit that referenced this issue Jul 25, 2022
aleks-f added a commit that referenced this issue Jul 26, 2022
* fix(Thread_POSIX): sleep() poor performance #3703

* chore(vscode): add file associations

* fix(TaskManager): waits for all threads in the ThreadPool #3704

* fix(Thread): call std::this_thread::sleep_for() to sleep #3703

* fix(PollSet): wakeup fd is never read #3708

* feat(Thread): Add Thread::set/getAffinity() #3709

* doc(Thread): Thread::trySleep() assertion #3710

* fix(PollSet): wakeup fd is never read (windows portion and some other optimizations) #3708

* feat(SocketReactor): improvements #3713

* chore(ThreadTest): add missing include

* fix(PollSet): wakeup fd is never read #3708

* fix(Any): #3682 #3683 #3692 #3712

* fix(mingw): lowercase winsock2 and iphlpapi to allow cross compile #3711

* feat(Thread): Add Thread::set/getAffinity() #3709

* chore(SocketReactor): one-liners inlined, removed redundant try/catch in dospatch, remove unused onBusy()

* feat(SocketReactor): add socket to ErrorNotification

* fix(SocketReactor): pollTimeout assignment and ConnectorTest leak
@aleks-f aleks-f added the fixed label Aug 2, 2022
@aleks-f aleks-f changed the title Poco::format recevies empty Vector<Any> Poco::format receives empty Vector<Any> Aug 7, 2022
@aleks-f aleks-f closed this as completed Aug 7, 2022
aleks-f added a commit that referenced this issue Aug 11, 2022
@aleks-f aleks-f modified the milestones: Release 1.12.2, Release 1.12.3 Oct 6, 2022
@aleks-f aleks-f reopened this Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants