YAML::Nodes alias rather than moving when using std::vector::erase, std::iter_swap and similar methods.

Aperta
#1,209 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Start by reproducing the failure with the vector erase test shown in the issue, then inspect the YAML::Node move constructor and move assignment behavior. The issue also mentions std::iter_swap and similar methods; verify whether those operations produce the same aliasing behavior. Done means erased and swapped vectors contain the expected distinct node values.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The following unit test fails

#include "gtest/gtest.h"
#include <yaml-cpp/yaml.h>
#include <vector>

TEST(VectorErase, ProducesVectorContainingCorrectElements) {
    YAML::Node a;
    a["name"] = "a";
    YAML::Node b;
    b["name"] = "b";
    YAML::Node c;
    c["name"] = "c";
    std::vector<YAML::Node> vec{a, b, c};
    vec.erase(vec.begin());
    EXPECT_EQ(vec[0]["name"].as<std::string>(), "b");
}

When vec.erase(vec.begin()) is called, instead of vec containing names {"b", "c"}, it instead contains names {"c", "c"}.

My guess is that this is something to do with aliasing rather than copying when the vector elements are moved. This is likely an issue with the move constructor or move assignment of the Node.

I am using libcpp-yaml0.6, as I am currently limited to Ubuntu 20.04.

Lingua principale
C++
Stelle
6.1k
Fork
2.2k
Merge medio
22h 2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jbeder/yaml-cpp

Tutte le issue di jbeder/yaml-cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.