[glom/glom-1-32] Document:remove_field(): Remove from the vector, not a copy.



commit 628637999f14b9bd947bd0ae24c974c4e84af05a
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jun 20 20:46:47 2017 +0200

    Document:remove_field(): Remove from the vector, not a copy.
    
    And test this.
    This regression was probably introduced by the conversion to use
    auto with C++11.

 glom/libglom/document/document.cc      |    2 +-
 tests/test_document_load_and_change.cc |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 1b4b5a8..eb0f633 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -717,7 +717,7 @@ void Document::remove_field(const Glib::ustring& table_name, const Glib::ustring
   const auto table_info = get_table_info(table_name);
   if(table_info)
   {
-    auto vecFields = table_info->m_fields;
+    auto& vecFields = table_info->m_fields;
     auto iterFind = find_if_same_name(vecFields, field_name);
     if(iterFind != vecFields.end()) //If it was found:
     {
diff --git a/tests/test_document_load_and_change.cc b/tests/test_document_load_and_change.cc
index b953cac..9cfd1e1 100644
--- a/tests/test_document_load_and_change.cc
+++ b/tests/test_document_load_and_change.cc
@@ -168,6 +168,15 @@ int main()
 
   //Remove a field from the whole document:
   document->remove_field("publisher", "publisher_id");
+
+  //Check that the old field name is not used.
+  auto field =
+    document->get_field("publisher", "publisher_id");
+  if (field) {
+    std::cerr << G_STRFUNC << ": Failure: The removed field name still exists.\n";
+    return EXIT_FAILURE;
+  }
+
   if(field_is_on_a_layout(document, "publisher", "publisher_id"))
   {
     std::cerr << G_STRFUNC << ": Failure: The removed field name is still used on a layout.\n";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]