Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6787157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:19:55+00:00 2026-05-26T17:19:55+00:00

I faced a problem using a Boost variant. I have a segmentation fault when

  • 0

I faced a problem using a Boost variant. I have a segmentation fault when the variant gets destructed.

The weird thing is that this segmentation fault occurs only when I do not activate the optimizations of the compiler (GCC in my case). For example, in O1, O2, O3 mode, I have no problem running my code.

My variant is defined like that :

typedef boost::variant<
            ASTFunctionCall, 
            ASTSwap, 
            ASTDeclaration,
            ASTAssignment, 
            ASTIf,
            ASTWhile,
            ASTForeach,
            ASTFor>
        ASTInstruction;

All the elements of the variant are some Deferred. The Deferred construct enable the deferred construction of objects. That seems that the object is not constructed before there is an access to one of its fields. The real object is backed with a shared_ptr.

And the error occurs from the destruction of a parent :

struct FunctionDeclaration { 
    std::shared_ptr<FunctionContext> context;
    std::string returnType;
    std::string functionName;
    std::string mangledName;
    std::vector<FunctionParameter> parameters;
    std::vector<ASTInstruction> instructions;
};

When the vector of instructions gets deleted, the segmentation fault occurs when the delete of the variant occurs at this specific function :

0x0000000000d71972 in boost::variant < eddic::Deferred < eddic::FunctionCall, std::shared_ptr < eddic::FunctionCall > >, eddic::Deferred >, eddic::Deferred < eddic::Declaration, std::shared_ptr < eddic::Declaration> >, eddic::Deferred < eddic::Assignment, std::shared_ptr < eddic::Assignment > >, eddic::Deferred < eddic::If, std::shared_ptr < eddic::If > >, eddic::Deferred < eddic::While, std::shared_ptr < eddic::While> >, eddic::Deferred < eddic::Foreach, std::shared_ptr < eddic::Foreach> >, eddic::Deferred < eddic::For, std::shared_ptr < eddic::For> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>::using_backup() const ()

EDIT 2 : After removing recursive_wrapper and intrusive_ptr to test, the error is now an assert of boost : Boost.Variant internal error: which out of range.

Is there some limitations on variant for destructions ? Like some kind of classes that we cannot put in a variant ?

Thanks in advance for any idea relating to this problem

EDIT : Can it comes from the fact that the variant contains several times a Deferred, Deferred, … ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:19:56+00:00Added an answer on May 26, 2026 at 5:19 pm

    I don’t know exactly what semantics you need, but could you simplify the variant structure tree like so:

    typedef boost::variant<
            ASTFunctionCall, 
            ASTSwap, 
            ASTDeclaration,
            ASTAssignment, 
            boost::recursive_wrapper<
                boost::variant<ASTIf, ASTWhile, ASTForeach, ASTFor> >
        ASTInstruction;
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of weird problem. I have been using HttpWebRequest for a long
I have faced this problem quite often during the last couple of months, during
We've faced strange problem. We have log on service, that authenticates user, adds auth
I seem to have faced this problem many times and I wanted to ask
I have faced a problem using rowcount in function in sql server 2000. It
I faced a problem while using threading for the first time, In an SWT
I faced with problem that geomap by google fails with JQuery together in Internet
I recently faced a problem of presenting the output of simple genetic algorithm that
Today I faced a strange problem in C#. I have an ASP.NET page where
We have recently been faced with the problem of porting our C++ framework to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.