Date: Mon, 20 Apr 2026 20:00:44 +0500
Relying on external tools for reporting errors is always unreliable. What
one would need is standard adapter. Using macros or external tools for
something as simple as an adaptor should be avoided. Until c++ provides
adaptors, I would say make it yourself. It's simple:
1.that is to make an adaptor where you make all default copy constructors
and copy assignment operators explicit.
2.provide a conversion operators to bool that returns the underlying bool
3. constructor that takes a bool argument and constructs the underlying
bool.
Problem fixed, right?
No need for macros.
On Mon, 20 Apr 2026, 6:31 pm Alejandro Colomar via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> Hi,
>
> On 2026-04-20T15:52:26+0300, sasho648 wrote:
> > Not sure if you have the entire conversation since this is an old thread.
> > But the previous example I had was:
> >
> >
> >
> > I agree I have had bug where I was doing:
> >
> > void set_property(const char *name, const char *default_value);
> > void set_property_bool(const char*name, bool default_value);
> >
> > And so I was calling the first with:
> >
> > set_property("prop", "true")
> >
> > But then when I call the second version with
> >
> > set_property_bool("prop", "true")
> >
> > It compiles fine and even works as expected until I changed it to
> >
> > set_property_bool("prop", "false")
> >
> > And then I banged my head for a while.
>
> Thanks!
>
> >
> > I also agree this was probably a bad design also but still.
> >
> > Which didn't have default parameters.
> >
> > And the topic is - should converson from pointer to bool like this be
> > allowed.
>
> Definitely yes, it should be allowed.
>
> You can request your compiler or static analyzer a voluntary diagnostic
> with some implementation-defined warning flag. But there are many
> places where conversion from pointer to bool is wanted.
>
> In C, you could force the parameter to be of a certain type in this
> specific API, with macros:
>
> alx_at_devuan:~/tmp$ cat g.c | nl -ba
> 1 #define set_property_bool(name, val)
> \
> 2 (
> \
> 3 _Generic(val, bool: (void)0),
> \
> 4 set_property_bool(name, val)
> \
> 5 )
> 6
> 7 void (set_property_bool)(const char *name, bool val);
> 8
> 9 int
> 10 main(void)
> 11 {
> 12 set_property_bool("foo", true);
> 13 set_property_bool("foo", "true");
> 14 }
> alx_at_devuan:~/tmp$ gcc g.c
> g.c: In function ‘main’:
> g.c:13:34: error: ‘_Generic’ selector of type ‘char *’ is not
> compatible with any association
> 13 | set_property_bool("foo", "true");
> | ^~~~~~
> g.c:3:18: note: in definition of macro ‘set_property_bool’
> 3 | _Generic(val, bool: (void)0),
> \
> | ^~~
>
> I ignore how to do that in C++, though.
>
>
> Cheers,
> Alex
>
> --
> <https://www.alejandro-colomar.es>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
one would need is standard adapter. Using macros or external tools for
something as simple as an adaptor should be avoided. Until c++ provides
adaptors, I would say make it yourself. It's simple:
1.that is to make an adaptor where you make all default copy constructors
and copy assignment operators explicit.
2.provide a conversion operators to bool that returns the underlying bool
3. constructor that takes a bool argument and constructs the underlying
bool.
Problem fixed, right?
No need for macros.
On Mon, 20 Apr 2026, 6:31 pm Alejandro Colomar via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> Hi,
>
> On 2026-04-20T15:52:26+0300, sasho648 wrote:
> > Not sure if you have the entire conversation since this is an old thread.
> > But the previous example I had was:
> >
> >
> >
> > I agree I have had bug where I was doing:
> >
> > void set_property(const char *name, const char *default_value);
> > void set_property_bool(const char*name, bool default_value);
> >
> > And so I was calling the first with:
> >
> > set_property("prop", "true")
> >
> > But then when I call the second version with
> >
> > set_property_bool("prop", "true")
> >
> > It compiles fine and even works as expected until I changed it to
> >
> > set_property_bool("prop", "false")
> >
> > And then I banged my head for a while.
>
> Thanks!
>
> >
> > I also agree this was probably a bad design also but still.
> >
> > Which didn't have default parameters.
> >
> > And the topic is - should converson from pointer to bool like this be
> > allowed.
>
> Definitely yes, it should be allowed.
>
> You can request your compiler or static analyzer a voluntary diagnostic
> with some implementation-defined warning flag. But there are many
> places where conversion from pointer to bool is wanted.
>
> In C, you could force the parameter to be of a certain type in this
> specific API, with macros:
>
> alx_at_devuan:~/tmp$ cat g.c | nl -ba
> 1 #define set_property_bool(name, val)
> \
> 2 (
> \
> 3 _Generic(val, bool: (void)0),
> \
> 4 set_property_bool(name, val)
> \
> 5 )
> 6
> 7 void (set_property_bool)(const char *name, bool val);
> 8
> 9 int
> 10 main(void)
> 11 {
> 12 set_property_bool("foo", true);
> 13 set_property_bool("foo", "true");
> 14 }
> alx_at_devuan:~/tmp$ gcc g.c
> g.c: In function ‘main’:
> g.c:13:34: error: ‘_Generic’ selector of type ‘char *’ is not
> compatible with any association
> 13 | set_property_bool("foo", "true");
> | ^~~~~~
> g.c:3:18: note: in definition of macro ‘set_property_bool’
> 3 | _Generic(val, bool: (void)0),
> \
> | ^~~
>
> I ignore how to do that in C++, though.
>
>
> Cheers,
> Alex
>
> --
> <https://www.alejandro-colomar.es>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-04-20 15:01:06
