summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-07-12 09:07:27 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-07-12 09:07:27 -0400
commitb1e44484a5702c840d8ab8db1b09121c1d43b126 (patch)
treeb96209f4af51649953b2b1eb3824af0dba0e136a /src
parentc001a8146bcc366780cd50fa51e8f91cfd2b1d5c (diff)
cxx: remove compilation warnings in C++ code, from both gcc and clang
Summary: Remove almost all the compilation warnings from C++ code. Only explicit warnings using the `#warning` preprocessor directive remain. Some warnings had to be suppressed with `#pragma` directives because the behavior they were warning about is intended in some specific places. Code comments were added in such situations. Added a generator that creates `#pragma` directives in order to suppress warnings in all generated C++ headers. Currently `-Wignored-qualifiers` is the only warning category being suppressed. The innocuous const qualifiers that it points are inoffensive and have no effect in compilation at all. They are also hard to track in generation since they can emerge from different types in many places. To ease the generation of the warning suppressors an utility constructor was added to `efl::eolian::grammar::attributes::unused_type`. Add constructors to `eolian_mono::class_context` to default initialize its internal string and avoid field initialization warnings. Test Plan: `meson test` Reviewers: lauromoura, felipealmeida, zmike, segfaultxavi Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D9275
Diffstat (limited to 'src')
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh2
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh10
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh6
-rw-r--r--src/bin/eolian_mono/eolian/mono/type_impl.hh2
-rw-r--r--src/bindings/cxx/eina_cxx/eina_optional.hh8
-rw-r--r--src/bindings/cxx/eldbus_cxx/eldbus_service.hh20
-rw-r--r--src/lib/eolian_cxx/grammar/attributes.hpp5
-rw-r--r--src/lib/eolian_cxx/grammar/class_implementation.hpp7
-rw-r--r--src/lib/eolian_cxx/grammar/generator.hpp2
-rw-r--r--src/lib/eolian_cxx/grammar/header.hpp3
-rw-r--r--src/lib/eolian_cxx/grammar/ignore_warning.hpp48
-rw-r--r--src/lib/eolian_cxx/grammar/type_impl.hpp2
-rw-r--r--src/lib/ephysics/ephysics_quaternion.cpp1
-rw-r--r--src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc2
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_optional.cc7
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_ptrlist.cc2
16 files changed, 114 insertions, 13 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index d5d57c4..ef4f5f4 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -1,5 +1,5 @@
1#ifndef EOLIAN_MONO_EVENTS_HH 1#ifndef EOLIAN_MONO_EVENTS_HH
2#define EOLINA_MONO_EVENTS_HH 2#define EOLIAN_MONO_EVENTS_HH
3 3
4#include <iterator> 4#include <iterator>
5 5
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index dc72696..985e373 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -21,6 +21,16 @@ struct class_context
21 }; 21 };
22 wrapper_kind current_wrapper_kind; 22 wrapper_kind current_wrapper_kind;
23 std::string name; 23 std::string name;
24
25 class_context(wrapper_kind current_wrapper_kind)
26 : current_wrapper_kind(current_wrapper_kind)
27 , name()
28 {}
29
30 class_context(wrapper_kind current_wrapper_kind, std::string const& name)
31 : current_wrapper_kind(current_wrapper_kind)
32 , name(name)
33 {}
24}; 34};
25 35
26struct indentation_context 36struct indentation_context
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
index d3fcbfa..ce16c9a 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
@@ -183,6 +183,7 @@ struct marshall_type_visitor_generate
183 , is_out 183 , is_out
184 , is_return 184 , is_return
185 , is_ptr 185 , is_ptr
186 , false
186 , is_special_subtype 187 , is_special_subtype
187 }(r); 188 }(r);
188 } 189 }
@@ -195,6 +196,7 @@ struct marshall_type_visitor_generate
195 , is_out 196 , is_out
196 , is_return 197 , is_return
197 , is_ptr 198 , is_ptr
199 , false
198 , is_special_subtype 200 , is_special_subtype
199 }(regular); 201 }(regular);
200 } 202 }
@@ -208,6 +210,7 @@ struct marshall_type_visitor_generate
208 , is_out 210 , is_out
209 , is_return 211 , is_return
210 , is_ptr 212 , is_ptr
213 , false
211 , is_special_subtype 214 , is_special_subtype
212 }(klass_name); 215 }(klass_name);
213 } 216 }
@@ -253,7 +256,7 @@ struct marshall_type_visitor_generate
253 auto default_match = [&] (attributes::complex_type_def const& complex) 256 auto default_match = [&] (attributes::complex_type_def const& complex)
254 { 257 {
255 regular_type_def no_pointer_regular = complex.outer; 258 regular_type_def no_pointer_regular = complex.outer;
256 return visitor_type{sink, context, c_type, false}(no_pointer_regular) 259 return visitor_type{sink, context, c_type, false, false, false, false}(no_pointer_regular)
257 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context); 260 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context);
258 }; 261 };
259 262
@@ -286,6 +289,7 @@ struct marshall_type_visitor_generate
286 , is_out 289 , is_out
287 , is_return 290 , is_return
288 , is_ptr 291 , is_ptr
292 , false
289 , is_special_subtype 293 , is_special_subtype
290 }(complex); 294 }(complex);
291 } 295 }
diff --git a/src/bin/eolian_mono/eolian/mono/type_impl.hh b/src/bin/eolian_mono/eolian/mono/type_impl.hh
index 41cdf92..abfa6e9 100644
--- a/src/bin/eolian_mono/eolian/mono/type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/type_impl.hh
@@ -412,7 +412,7 @@ struct visitor_generate
412 // pointers.swap(no_pointer_regular.pointers); 412 // pointers.swap(no_pointer_regular.pointers);
413 // if(is_out) 413 // if(is_out)
414 // pointers.push_back({{attributes::qualifier_info::is_none, {}}, true}); 414 // pointers.push_back({{attributes::qualifier_info::is_none, {}}, true});
415 return visitor_type{sink, context, c_type, false}(no_pointer_regular) 415 return visitor_type{sink, context, c_type, false, false, false, false, false}(no_pointer_regular)
416 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context) 416 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context)
417 ; 417 ;
418 // && detail::generate_pointers(sink, pointers, *context, false); 418 // && detail::generate_pointers(sink, pointers, *context, false);
diff --git a/src/bindings/cxx/eina_cxx/eina_optional.hh b/src/bindings/cxx/eina_cxx/eina_optional.hh
index 91b38c3..70a5cc2 100644
--- a/src/bindings/cxx/eina_cxx/eina_optional.hh
+++ b/src/bindings/cxx/eina_cxx/eina_optional.hh
@@ -387,7 +387,15 @@ private:
387 void _construct(U&& object) 387 void _construct(U&& object)
388 { 388 {
389 assert(!is_engaged()); 389 assert(!is_engaged());
390 // NOTE: the buffer memory is intended to be in an
391 // uninitialized state here.
392 // So this warning can be disabled.
393#pragma GCC diagnostic push
394#ifndef __clang__
395#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
396#endif
390 new (&buffer) T(std::forward<U>(object)); 397 new (&buffer) T(std::forward<U>(object));
398#pragma GCC diagnostic pop
391 engaged = true; 399 engaged = true;
392 } 400 }
393 401
diff --git a/src/bindings/cxx/eldbus_cxx/eldbus_service.hh b/src/bindings/cxx/eldbus_cxx/eldbus_service.hh
index 6a4919c..31c3386 100644
--- a/src/bindings/cxx/eldbus_cxx/eldbus_service.hh
+++ b/src/bindings/cxx/eldbus_cxx/eldbus_service.hh
@@ -293,11 +293,23 @@ void _create_methods_specification_impl(Method const& method, Eldbus_Method2& el
293 293
294 eldbus::_fill_methods(*out_params, method.outs); 294 eldbus::_fill_methods(*out_params, method.outs);
295 295
296 // NOTE: C pointer magic performed under the hood requires this conversion
297 // between incompatible function pointer types.
298 // C++ always raises a warning for such conversions, so this warning
299 // can be disabled just here.
300#pragma GCC diagnostic push
301#ifndef __clang__
302#pragma GCC diagnostic ignored "-Wcast-function-type"
303#endif
304 Eldbus_Method_Cb method_cb =
305 reinterpret_cast<Eldbus_Method_Cb>
306 (static_cast<Eldbus_Method_Data_Cb>
307 (&_method_callback<typename Method::function_type
308 , typename Method::ins_type, typename Method::outs_type>));
309#pragma GCC diagnostic pop
310
296 eldbus_method = {{method.name, &(*in_params)[0], &(*out_params)[0] 311 eldbus_method = {{method.name, &(*in_params)[0], &(*out_params)[0]
297 , reinterpret_cast<Eldbus_Method_Cb> 312 , method_cb
298 (static_cast<Eldbus_Method_Data_Cb>
299 (&_method_callback<typename Method::function_type
300 , typename Method::ins_type, typename Method::outs_type>))
301 , ELDBUS_METHOD_FLAG_HAS_DATA} 313 , ELDBUS_METHOD_FLAG_HAS_DATA}
302 , new std::tuple<typename Method::function_type 314 , new std::tuple<typename Method::function_type
303 , typename Method::ins_type, typename Method::outs_type 315 , typename Method::ins_type, typename Method::outs_type
diff --git a/src/lib/eolian_cxx/grammar/attributes.hpp b/src/lib/eolian_cxx/grammar/attributes.hpp
index d33fcf2..b3efcce 100644
--- a/src/lib/eolian_cxx/grammar/attributes.hpp
+++ b/src/lib/eolian_cxx/grammar/attributes.hpp
@@ -9,7 +9,10 @@ namespace efl { namespace eolian { namespace grammar {
9 9
10namespace attributes { 10namespace attributes {
11 11
12struct unused_type {}; 12struct unused_type {
13 unused_type() = default;
14 unused_type(std::nullptr_t) {}
15};
13unused_type const unused = {}; 16unused_type const unused = {};
14 17
15template <int N, typename Tuple, typename Enable = void> 18template <int N, typename Tuple, typename Enable = void>
diff --git a/src/lib/eolian_cxx/grammar/class_implementation.hpp b/src/lib/eolian_cxx/grammar/class_implementation.hpp
index 615ee60..7428335 100644
--- a/src/lib/eolian_cxx/grammar/class_implementation.hpp
+++ b/src/lib/eolian_cxx/grammar/class_implementation.hpp
@@ -15,6 +15,7 @@
15#include "grammar/type_impl.hpp" 15#include "grammar/type_impl.hpp"
16#include "grammar/attribute_reorder.hpp" 16#include "grammar/attribute_reorder.hpp"
17#include "grammar/part_implementation.hpp" 17#include "grammar/part_implementation.hpp"
18#include "grammar/ignore_warning.hpp"
18 19
19namespace efl { namespace eolian { namespace grammar { 20namespace efl { namespace eolian { namespace grammar {
20 21
@@ -42,6 +43,9 @@ struct class_implementation_generator
42 .generate(sink, std::make_tuple(cls.namespaces, cls.cxx_name), add_lower_case_context(ctx))) 43 .generate(sink, std::make_tuple(cls.namespaces, cls.cxx_name), add_lower_case_context(ctx)))
43 return false; 44 return false;
44 45
46 if(!as_generator(ignore_warning_begin).generate(sink, nullptr, ctx))
47 return false;
48
45#ifndef USE_EOCXX_INHERIT_ONLY 49#ifndef USE_EOCXX_INHERIT_ONLY
46 if(!as_generator( 50 if(!as_generator(
47 (namespaces 51 (namespaces
@@ -71,6 +75,9 @@ struct class_implementation_generator
71 )).generate(sink, std::make_tuple(cls.namespaces, cls.functions, cpp_namespaces, cls.cxx_name, cls.parts), ctx)) 75 )).generate(sink, std::make_tuple(cls.namespaces, cls.functions, cpp_namespaces, cls.cxx_name, cls.parts), ctx))
72 return false; 76 return false;
73 77
78 if(!as_generator(ignore_warning_end).generate(sink, nullptr, ctx))
79 return false;
80
74 if(!as_generator("#endif\n").generate(sink, std::make_tuple(), ctx)) 81 if(!as_generator("#endif\n").generate(sink, std::make_tuple(), ctx))
75 return false; 82 return false;
76 83
diff --git a/src/lib/eolian_cxx/grammar/generator.hpp b/src/lib/eolian_cxx/grammar/generator.hpp
index 6d0be7e..25fff51 100644
--- a/src/lib/eolian_cxx/grammar/generator.hpp
+++ b/src/lib/eolian_cxx/grammar/generator.hpp
@@ -46,7 +46,7 @@ struct is_eager_generator<T volatile const&> : is_eager_generator<T> {};
46// struct is_generator<T> : is_eager_generator<T> {}; 46// struct is_generator<T> : is_eager_generator<T> {};
47 47
48template <typename G, typename Enable = typename std::enable_if<is_eager_generator<G>::value>::type> 48template <typename G, typename Enable = typename std::enable_if<is_eager_generator<G>::value>::type>
49G as_generator(G&& g) { return g; } 49G as_generator(G g) { return g; }
50 50
51 51
52} } } 52} } }
diff --git a/src/lib/eolian_cxx/grammar/header.hpp b/src/lib/eolian_cxx/grammar/header.hpp
index 2943540..f749584 100644
--- a/src/lib/eolian_cxx/grammar/header.hpp
+++ b/src/lib/eolian_cxx/grammar/header.hpp
@@ -11,6 +11,7 @@
11#include "class_definition.hpp" 11#include "class_definition.hpp"
12#include "class_declaration.hpp" 12#include "class_declaration.hpp"
13#include "implementation_include_directive.hpp" 13#include "implementation_include_directive.hpp"
14#include "ignore_warning.hpp"
14 15
15namespace efl { namespace eolian { namespace grammar { 16namespace efl { namespace eolian { namespace grammar {
16 17
@@ -27,11 +28,13 @@ auto class_header =
27 << *class_declaration // sequence<class> | class 28 << *class_declaration // sequence<class> | class
28 << *class_forward_declaration // sequence<class> | class 29 << *class_forward_declaration // sequence<class> | class
29 << string // extra header <string> 30 << string // extra header <string>
31 << ignore_warning_begin
30 << "\nnamespace eo_cxx {\n" 32 << "\nnamespace eo_cxx {\n"
31 << *base_class_definition // sequence<class> | class 33 << *base_class_definition // sequence<class> | class
32 << "}\n" 34 << "}\n"
33 << *class_definition // sequence<class> | class 35 << *class_definition // sequence<class> | class
34 // << *implementation_include_directive 36 // << *implementation_include_directive
37 << ignore_warning_end
35 ] 38 ]
36 ; 39 ;
37 40
diff --git a/src/lib/eolian_cxx/grammar/ignore_warning.hpp b/src/lib/eolian_cxx/grammar/ignore_warning.hpp
new file mode 100644
index 0000000..d3d2a6e
--- /dev/null
+++ b/src/lib/eolian_cxx/grammar/ignore_warning.hpp
@@ -0,0 +1,48 @@
1#ifndef EOLIAN_CXX_IGNORE_WARNING_HH
2#define EOLIAN_CXX_IGNORE_WARNING_HH
3
4#include "grammar/generator.hpp"
5
6namespace efl { namespace eolian { namespace grammar {
7
8struct ignore_warning_begin_generator
9{
10 template <typename OutputIterator, typename Context>
11 bool generate(OutputIterator sink, attributes::unused_type, Context const& context) const
12 {
13 return as_generator(
14 "\n"
15 "#pragma GCC diagnostic push\n"
16 "#pragma GCC diagnostic ignored \"-Wignored-qualifiers\"\n"
17 "\n"
18 ).generate(sink, nullptr, context);
19 }
20};
21
22struct ignore_warning_end_generator
23{
24 template <typename OutputIterator, typename Context>
25 bool generate(OutputIterator sink, attributes::unused_type, Context const& context) const
26 {
27 return as_generator(
28 "\n#pragma GCC diagnostic pop\n\n"
29 ).generate(sink, nullptr, context);
30 }
31};
32
33template <>
34struct is_eager_generator<ignore_warning_begin_generator> : std::true_type {};
35template <>
36struct is_generator<ignore_warning_begin_generator> : std::true_type {};
37
38template <>
39struct is_eager_generator<ignore_warning_end_generator> : std::true_type {};
40template <>
41struct is_generator<ignore_warning_end_generator> : std::true_type {};
42
43ignore_warning_begin_generator constexpr ignore_warning_begin = {};
44ignore_warning_end_generator constexpr ignore_warning_end = {};
45
46} } }
47
48#endif
diff --git a/src/lib/eolian_cxx/grammar/type_impl.hpp b/src/lib/eolian_cxx/grammar/type_impl.hpp
index ca73a14..c5bd4d8 100644
--- a/src/lib/eolian_cxx/grammar/type_impl.hpp
+++ b/src/lib/eolian_cxx/grammar/type_impl.hpp
@@ -348,7 +348,7 @@ struct visitor_generate
348 // pointers.swap(no_pointer_regular.pointers); 348 // pointers.swap(no_pointer_regular.pointers);
349 // if(is_out) 349 // if(is_out)
350 // pointers.push_back({{attributes::qualifier_info::is_none, {}}, true}); 350 // pointers.push_back({{attributes::qualifier_info::is_none, {}}, true});
351 return visitor_type{sink, context, c_type, false}(no_pointer_regular) 351 return visitor_type{sink, context, c_type, false, false}(no_pointer_regular)
352 && as_generator("<" << (type % ", ") << ">").generate(sink, complex.subtypes, *context) 352 && as_generator("<" << (type % ", ") << ">").generate(sink, complex.subtypes, *context)
353 ; 353 ;
354 // && detail::generate_pointers(sink, pointers, *context, false); 354 // && detail::generate_pointers(sink, pointers, *context, false);
diff --git a/src/lib/ephysics/ephysics_quaternion.cpp b/src/lib/ephysics/ephysics_quaternion.cpp
index 899204d..bf1b915 100644
--- a/src/lib/ephysics/ephysics_quaternion.cpp
+++ b/src/lib/ephysics/ephysics_quaternion.cpp
@@ -126,7 +126,6 @@ ephysics_quaternion_euler_set(EPhysics_Quaternion *quat, double yaw, double pitc
126 return; 126 return;
127 } 127 }
128 128
129 bt_quat = btQuaternion();
130 bt_quat.setEuler(yaw / RAD_TO_DEG, pitch / RAD_TO_DEG, roll / RAD_TO_DEG); 129 bt_quat.setEuler(yaw / RAD_TO_DEG, pitch / RAD_TO_DEG, roll / RAD_TO_DEG);
131 _ephysics_quaternion_update(quat, &bt_quat); 130 _ephysics_quaternion_update(quat, &bt_quat);
132} 131}
diff --git a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
index 5ad5da5..749b8b0 100644
--- a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
+++ b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
@@ -14,7 +14,7 @@ void call_async(efl::eina::mutex& mutex, efl::eina::condition_variable& cond, in
14{ 14{
15 efl::ecore::main_loop_thread_safe_call_async 15 efl::ecore::main_loop_thread_safe_call_async
16 ( 16 (
17 [&mutex,&cond,&done] 17 [&mutex,&done]
18 { 18 {
19 std::cout << "yeah" << std::endl; 19 std::cout << "yeah" << std::endl;
20 efl::eina::unique_lock<efl::eina::mutex> l(mutex); 20 efl::eina::unique_lock<efl::eina::mutex> l(mutex);
diff --git a/src/tests/eina_cxx/eina_cxx_test_optional.cc b/src/tests/eina_cxx/eina_cxx_test_optional.cc
index 381198c..5eb2631 100644
--- a/src/tests/eina_cxx/eina_cxx_test_optional.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_optional.cc
@@ -102,7 +102,14 @@ EFL_START_TEST(eina_cxx_optional_assignment)
102 102
103 assert(!a); assert(b); assert(c); assert(d); 103 assert(!a); assert(b); assert(c); assert(d);
104 104
105 // NOTE: resistance to self assignment is exactly what is being tested here,
106 // so this compilation warning can be suppressed.
107#pragma GCC diagnostic push
108#ifdef __clang__
109#pragma GCC diagnostic ignored "-Wself-assign-overloaded"
110#endif
105 a = a; 111 a = a;
112#pragma GCC diagnostic pop
106 ck_assert(a == a); 113 ck_assert(a == a);
107 ck_assert(!a); 114 ck_assert(!a);
108 115
diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
index be6b163..12c375a 100644
--- a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
@@ -385,7 +385,7 @@ EFL_START_TEST(eina_cxx_ptrlist_constructors)
385 efl::eina::list<wrapper> list2(10, w1); 385 efl::eina::list<wrapper> list2(10, w1);
386 ck_assert(list2.size() == 10); 386 ck_assert(list2.size() == 10);
387 ck_assert(std::find_if(list2.begin(), list2.end() 387 ck_assert(std::find_if(list2.begin(), list2.end()
388 , [&list2, w2] (wrapper i) 388 , [w2] (wrapper i)
389 { 389 {
390 return i == w2; 390 return i == w2;
391 } 391 }