conan icon indicating copy to clipboard operation
conan copied to clipboard

[bug] conan.tools.build.check_min_cppstd does infer default cppstd as documented

Open puetzk opened this issue 1 year ago • 0 comments

Describe the bug

https://docs.conan.io/2/reference/tools/build.html#conan-tools-build-check-min-cppstd says that check_*_cppstd should be able to infer the default cppstd from compiler.version in cases where it has not been overridden:

It not settings.compiler.cppstd, the tool will use compiler to compare (reading the default from cppstd_default)

And does contain a function to derive this information https://github.com/conan-io/conan/blob/c233c627e72c15288290a0f55d9f5832051c1c61/conan/tools/build/cppstd.py#L78

However, it doesn't seem to actually call this function anywhere - if the profile does not expliticly set compiler.cppstd, it simply errors out with

This doesn't match the documentation, or the behavior of the old (conan 1.x) conans.tools.check_min_cppstd, where such defaulting was also documented and did actually work.

test/1.0: Invalid: The compiler.cppstd is not defined for this configuration

I found a note at https://github.com/conan-io/conan/issues/11003#issuecomment-1095618541 suggesting that the intent might have been to make cppstd compulsory, but if so that seemingly never happened - the default settings.yml is still happy to allow compiler.cppstd =null, https://github.com/conan-io/conan/blob/c233c627e72c15288290a0f55d9f5832051c1c61/conans/client/conf/init.py#L102

and this still causes the same https://github.com/conan-io/conan/blob/c233c627e72c15288290a0f55d9f5832051c1c61/conan/tools/build/cppstd.py#L155-L157

in conan 2.3.1 that it does in conan 1.x

So it seems that either the code should support defaults (as its documentation says, and its predecessor did) or the documentation should at least not claim that it does. Preferably the former, since the documented behavior matches the old tools and seems desireable (there's really no reason validate() needs to fail if the compiler's defaults satisfy it...

How to reproduce it

ubuntu 22.04 (11.4.0)

from conan import ConanFile
from conan.tools.build import check_min_cppstd

class TestConan(ConanFile):
    name = "test"
    version = "0.1"

    def validate(self):
        check_min_cppstd(self, "14")

conan create .

======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.libcxx=libstdc++11 compiler.version=11 os=Linux

Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.libcxx=libstdc++11 compiler.version=11 os=Linux

======== Computing dependency graph ======== Graph root cli Requirements test/0.1#12fed99e8a78e059aec5714f29af6be4 - Cache

======== Computing necessary packages ======== Requirements test/0.1#12fed99e8a78e059aec5714f29af6be4:da39a3ee5e6b4b0d3255bfef95601890afd80709 - Invalid ERROR: There are invalid packages: test/0.1: Invalid: The compiler.cppstd is not defined for this configuration

puetzk avatar May 24 '24 21:05 puetzk