question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cppstd setting has no default value

See original GitHub issue

To help us debug your issue please explain:

  • I’ve read the CONTRIBUTING guide.
  • I’ve specified the Conan version, operating system version and any tool that can be relevant.
  • I’ve explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

Hello,

First off, I would like to say thank you to everyone involved in this awesome project.

I have read the how-to article about managing the C++ standard, where it is stated that “By default Conan will detect the default standard of your compiler to not generate different binary packages.”

My conan package uses a custom build system for which I need to manually parse and pass the CXX flags. I caught the error when I tried to pass a flag for the standard with the following code:

if "gnu" in self.settings.cppstd:
    cxx_flags.append("-std=gnu++%s" % str(self.settings.cppstd).replace("gnu", ""))
else:
    cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
TypeError: __str__ returned non-string (type NoneType)

Upon further debugging I spotted the following custom warning being outputted:

if not self.settings.cppstd:
    self.output.warn("cppstd empty")

My recipe specified cppstd in the settings and I did not pass a command line argument and the settings.cppstd was None instead of a detected default value. I ended up with the following temporary workaround in my configure method:

 if not self.settings.cppstd:
     self.output.warn("cppstd empty, setting default")
     from conans.client.build.cppstd_flags import cppstd_default
     self.settings.cppstd = cppstd_default(self.settings.get_safe("compiler"),
                                           self.settings.get_safe("compiler.version"))

I would assume that the default value should be set for the user as well as internally when no cppstd command line argument is given but it is specified in the recipe.

For the record, not having the cppstd specified in the recipe, (properly) throws an exception on the following line:

if not self.settings.cppstd:
        ConanException: 'settings.cppstd' doesn't exist

Software information: I’m currently using Conan version 1.2.0 on

ProductName:    Mac OS X
ProductVersion: 10.13.3
BuildVersion:   17D102

with

Xcode 9.2
Build version 9C40b

and Python 3.6.4 installed from brew

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
T1T4Ncommented, Apr 3, 2018

Awesome! Once again, a big thank you to everyone who is involved with the development of this project.

1reaction
T1T4Ncommented, Apr 3, 2018

Hi @lasote, @memsharded,

Following your last two comments, I have adjusted my code not to use the cppstd_default function and I have adjusted the appending of the flag to the following:

if self.settings.get_safe('cppstd'):
    if "gnu" in self.settings.cppstd:
        cxx_flags.append("-std=gnu++%s" % str(self.settings.cppstd).replace("gnu", ""))
    else:
        cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
else:
    self.output.info("cppstd not explicitly defined, using default")

My question was answered and the issue can be closed as it is in fact the intended behavior. However I would suggest adding to the documentation that the cppstd has a default value of None.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to manage C++ standard [EXPERIMENTAL] - Conan Docs
The setting representing the C++ standard is compiler.cppstd . The detected default profile doesn't set any value for the compiler.cppstd setting,.
Read more >
If I specify a default value for an argument of type "std::string ...
There is no technical issue, but philosophically creating a temporary std::string at each call is not so nice. Especially with libstdc++ ...
Read more >
Customize default settings in Visual Studio Code C++ projects
So you can set a global value for C_Cpp.default.cppStandard in your "User" settings and have it apply to all of the folders you...
Read more >
std::exchange - cppreference.com
Replaces the value of obj with new_value and returns the old value of obj ... Since the second template parameter has a default...
Read more >
std::optional: How, when, and why - C++ Team Blog
optional is mandatory · easily discern the no-value case from the value-found case, unlike for the “return a default value” solution, · report...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found