compiler error : get_if<> with a variant enum ?

Francine Sauvage francine.sauvage at
Thu Oct 20 19:35:47 AEDT 2022

Hi Patrick,

Many thanks to answer me.

I prepared a mail for 2 days, but ... I am still testing your suggestions.

I included the generated server.hpp but not the generated server.cpp as a library.
It could explain my problem.
I am not able to add my enum (ModulesTypes) in the variant list.

It should disturb the generated mechanism.
So I added the generated library (similar/specific phosphor-dbus-interfaces)

I'll let you know,


Francine SAUVAGE
Team Leader - R&D, BDS
Atos France
Mobile: +33 6 21 43 11 21
Avenue Jean Jaurès - France
TT: [Wednesday or Thurday(2nd week of month) ] - Friday] 
OoO : October 31

-----Message d'origine-----
De : Patrick Williams <patrick at> 
Envoyé : mardi 18 octobre 2022 01:37
À : Francine Sauvage <francine.sauvage at>
Cc : openbmc at
Objet : Re: compiler error : get_if<> with a variant enum ?

On Mon, Oct 17, 2022 at 08:13:20AM +0000, Francine Sauvage wrote:
> const auto* flexible_module_type = 
> std::get_if<sdbusplus::xyz::openbmc_project::Inventory::Item::server::
> FlexibleModule::ModuleTypes>(&flexible_prop_map_iterator->second);
> ** I tried to replace auto with 
> sdbusplus::xyz::openbmc_project::Inventory::Item::server::FlexibleModu
> le::ModuleTypes>
> No success.
> Error is :
> bmcweb/1.0+git1.0-r0/recipe-sysroot/usr/include/c++/10.2.0/variant:115
> 0:42: error: static assertion failed: T must occur exactly once in 
> alternatives static_assert(__detail::__variant::__exactly_once<_Tp, 
> _Types...>,

What type is `flexible_prop_map_iterator->second`?  It seems likely it is a variant that doesn't have the enumeration type in the list of contained types.  "T must occur exactly one in alternatives" seems to be saying that `ModuleTypes` wasn't part of the underlying variant types.

Patrick Williams

More information about the openbmc mailing list