Error enumeration value not handled in switch

I am trying to compile following code without warnings: while (window.pollEvent(event)) { switch (event.type) { case sf::Event::Closed: window.close(); ...

Be explicit

It depends on what you are trying to achieve. The governing rule is

It is better to be explicit.

Omitting the cases simply makes it look like you forgot some. Being explicit assures subsequent readers of your code that you intended to do nothing for certain events.

In light of that, you have a couple of options:

Option 1 — add the default

default:
  break;

This suppresses the warning, and makes it clear that you don’t intend to handle the other event types here.

Option 2 — list each value

List each event type, followed by a break.
This is also explicit, and has the added bonus that, should you ever add an event type, the compiler will once again warn you that your switch is incomplete. This can be valuable when you have many switch statements, some of which need to be modified to do something new when an enum value is added.

What about a series of if statements?

I would not recommend using a series of if statements here. A switch is clearer, reduces the amount of typing, and (as you’ve seen) can produce better compiler warnings for cases you omitted.

Помоги компилятору помочь тебе

Время прочтения
18 мин

Просмотры 35K

Предисловие

Современные компиляторы обладают огромным количеством диагностик. И удивительно, что очень малая их часть включена по умолчанию.

Огромное количество претензий, которые предъявляют к языку C++ в этих ваших интернетах, — про сложность, небезопасность, стрельбу по ногам и т.п., — относятся как раз к тем случаям, когда люди просто не знают о том, что можно решить эти проблемы лёгким движением пальцев по клавиатуре.

Давайте же исправим эту вопиющую несправедливость, и прольём свет истины на возможности компилятора по предотвращению ошибок.

Содержание

  1. Ода компилятору
  2. Игнорировать нельзя исправить
  3. -Wall
  4. -Wextra
  5. -Wpedantic
  6. Нужно больше предупреждений
  7. -Werror
  8. Заключение
  9. Ссылки

Ода компилятору

Компилятор – лучший друг плюсовика. Компилятор — это не просто транслятор формального человекочитаемого языка в машинные коды. Компилятор — лучший помощник в написании программ.

Важная (и не единственная) помощь, которую оказывает компилятор — поиск ошибок. И я говорю не об опечатках, несовпадении типов и прочих синтаксических ошибках. Я говорю об огромном наборе ошибок, которые можно выловить с помощью механизма предупреждений.

Часто встречаю мнение о том, что предупреждений слишком много, они дают ложноположительные результаты, мешают работать, замыливают глаз, отвлекают от «настоящих» ошибок и т.п. Такое действительно бывает, но это большая редкость.

Игнорировать нельзя исправить

Большинство предупреждений — это не «бзик» компилятора, который можно просто проигнорировать. Предупреждение — это потенциальная ошибка. Предупреждение — это сигнал от компилятора о том, что написано одно, а требуется, возможно, что-то совершенно иное.

Поэтому программист должен помочь компилятору понять, как трактовать спорную ситуацию. То есть либо поправить свою ошибку, либо сообщить компилятору явно о том, что нужно верить программисту и делать именно то, что написано. Причём это поможет не только компилятору, но и человеку, который будет читать код. Лишний static_cast или пара скобок будут явно свидетельствовать о том, что имелось в виду именно то, что написано.

Далее я расскажу о наиболее важных на мой взгляд предупреждениях и покажу, какие ошибки можно отловить с их помощью.

Надеюсь, что данное не слишком занимательное чтиво поможет правильно поставить запятую в заголовке этого раздела.

Сразу хочу оговориться, что далее речь пойдёт исключительно о языке C++ и компиляторе GCC (впрочем, подавляющая часть информации актуальна и для компилятора Clang). Информацию о других компиляторах и языках придётся искать в соответствующих справочниках.

-Wall

-Wall — это «агрегатор» базовых предупреждений. В языке C++ он включает в себя длинный перечень предупреждений, каждое из которых будет рассмотрено отдельно (на самом деле, рассмотрены будут не все, а только те, которые непосредственно помогают выявлять ошибки).

Важно:

Несмотря на название, этот флаг включает далеко не все предупреждения, которые умеет обнаруживать компилятор.

В этом разделе:

  1. -Waddress
  2. -Warray-bounds=1
  3. -Wbool-compare
  4. -Wbool-operation
  5. -Wcatch-value
  6. -Wchar-subscripts
  7. -Wcomment
  8. -Wint-in-bool-context
  9. -Winit-self
  10. -Wlogical-not-parentheses
  11. -Wmaybe-uninitialized
  12. -Wmemset-elt-size
  13. -Wmemset-transposed-args
  14. -Wmisleading-indentation
  15. -Wmissing-attributes
  16. -Wmultistatement-macros
  17. -Wnonnull
  18. -Wnonnull-compare
  19. -Wparentheses
  20. -Wpessimizing-move
  21. -Wreorder
  22. -Wreturn-type
  23. -Wsequence-point
  24. -Wsign-compare
  25. -Wsizeof-pointer-div
  26. -Wsizeof-pointer-memaccess
  27. -Wstrict-aliasing
  28. -Wswitch
  29. -Wtautological-compare
  30. -Wtrigraphs
  31. -Wuninitialized
  32. -Wunused-function
  33. -Wunused-variable

-Waddress

Предупреждает о странной работе с адресами. Например, об использовании адреса функции в условном выражении. Такое может произойти, если забыть поставить скобки после имени функции:

bool func () {return false;}

int main ()
{
    if (func)
    {
        return 1;
    }
}

prog.cc: In function 'int main()':
prog.cc:5:9: warning: the address of 'bool func()' will never be NULL [-Waddress]
    5 |     if (func)
      |         ^~~~

Также этот флаг может спасти от типичной ошибки новичка — сравнения строкового литерала с адресом. Очевидно, программист хотел сравнить строки, но в результате сравнил два указателя:

int main ()
{
    const char * a = "abc";
    if (a == "abc")
    {
        return 0;
    }
}

Компилятор бдит:

prog.cc: In function 'int main()':
prog.cc:4:11: warning: comparison with string literal results in unspecified behavior [-Waddress]
    4 |     if (a == "abc")
      |         ~~^~~~~~~~

-Warray-bounds=1

Предупреждает о выходе за пределы массивов. Используется только вместе с -O2.

int main()
{
    int a[5] = {1, 2, 3, 4, 5};
    return a[5];
}

prog.cc: In function 'int main()':
prog.cc:4:15: warning: array subscript 5 is above array bounds of 'int [5]' [-Warray-bounds]
    4 |     return a[5];
      |            ~~~^
prog.cc:3:9: note: while referencing 'a'
    3 |     int a[5] = {1, 2, 3, 4, 5};
      |         ^

-Wbool-compare

Предупреждает о сравнении булева выражения с целым числом, которое нельзя трактовать как булево:

int main ()
{
    int n = 5;

    if ((n > 1) == 2)
    {
        return 0;
    }
}

prog.cc: In function 'int main()':
prog.cc:5:17: warning: comparison of constant '2' with boolean expression is always false [-Wbool-compare]
    5 |     if ((n > 1) == 2)
      |         ~~~~~~~~^~~~

-Wbool-operation

Предупреждает о подозрительных операциях с булевыми выражениями. Например, о побитовом отрицании:

int main ()
{
    bool b = true;
    auto c = ~b;
}

prog.cc: In function 'int main()':
prog.cc:4:15: warning: '~' on an expression of type 'bool' [-Wbool-operation]
    4 |     auto c = ~b;
      |               ^
prog.cc:4:15: note: did you mean to use logical not ('!')?

Что касается инкрементов и декрементов булевых переменных, то в C++17 это просто ошибки, безо всяких предупреждений.

-Wcatch-value

Предупреждает о обработчиках исключений, которые принимают полиморфные объекты по значению:

struct A
{
    virtual ~A () {};
};

struct B: A{};

int main ()
{
    try {}
    catch (A) {}
}

prog.cc: In function 'int main()':
prog.cc:11:12: warning: catching polymorphic type 'struct A' by value [-Wcatch-value=]
   11 |     catch (A) {}
      |            ^

Есть и более сильные версии предупреждения: -Wcatch-value=n (см. справку к компилятору).

-Wchar-subscripts

Предупреждает об обращении к массиву по индексу, тип которого char. А ведь char является знаковым на многих машинах:

int main ()
{
    int a[] = {1, 2, 3, 4};
    char index = 'a' - 'b';
    return a[index];
}

prog.cc: In function 'int main()':
prog.cc:5:14: warning: array subscript has type 'char' [-Wchar-subscripts]
    5 |     return a[index];
      |              ^~~~~

Предупреждает о наличии последовательности, начинающей новый комментарий (/*), внутри многострочного комментария, либо о разрыве строки при помощи обратного слеша внутри однострочного комментария.

int main ()
{
    /* asd /* fgh */
    //qwe
    rty
}

prog.cc:3:8: warning: "/*" within comment [-Wcomment]
    3 |     /* /* */
      |
prog.cc:4:5: warning: multi-line comment [-Wcomment]
    4 |     //ssd
      |     ^

-Wint-in-bool-context

Предупреждает о подозрительном использовании целых чисел там, где ожидаются булевы выражения, например, в условных выражениях:

int main ()
{
    int a = 5;
    if (a <= 4 ? 2 : 3)
    {
        return 0;
    }
}

prog.cc: In function 'int main()':
prog.cc:4:16: warning: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Wint-in-bool-context]
    4 |     if (a <= 4 ? 2 : 3)
      |         ~~~~~~~^~~~~~~

Другой пример — операции побитового сдвига в булевом контексте. Вполне вероятно, что здесь произошла опечатка, и имелся в виду не сдвиг, а сравнение:

int main ()
{
    for (auto a = 0; 1 << a; a++);
}

prog.cc: In function 'int main()':
prog.cc:3:24: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
    3 |     for (auto a = 0; 1 << a; a++);
      |                      ~~^~~~

А также сообщает о любых видах умножения в булевом контексте.

int main ()
{
    int a = 5;
    if (a * 5);
}

prog.cc: In function 'int main()':
prog.cc:4:11: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
    4 |     if (a * 5);
      |         ~~^~~

-Winit-self

Предупреждает об инициализации переменных самими сабями. Используется только вместе с флагом -Wuninitialized.

int main ()
{
    int i = i;
    return i;
}

prog.cc: In function 'int main()':
prog.cc:3:9: warning: 'i' is used uninitialized in this function [-Wuninitialized]
    3 |     int i = i;
      |         ^

-Wlogical-not-parentheses

Предупреждает об использовании логического отрицания в левой части сравнения. При этом если правая часть сравнения является сама по себе булевым выражением, то предупреждения не будет.

Используется для того, чтобы отлавливать подозрительные конструкции вроде следующей:

int main ()
{
    int a = 9;
    if (!a > 1);
}

prog.cc: In function 'int main()':
prog.cc:5:12: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
    5 |     if (!a > 1);
      |            ^
prog.cc:5:9: note: add parentheses around left hand side expression to silence this warning
    5 |     if (!a > 1);
      |         ^~
      |         ( )

Традиционный способ сообщить компилятору, что так и было задумано — поставить скобки, о чём и сообщает компилятор.

-Wmaybe-uninitialized

Предупреждает о том, что существует возможность использования непроинициализированной переменной.

int main (int argc, const char * argv[])
{
    int x;
    switch (argc)
    {
        case 1: x = 1;
            break;
        case 2: x = 4;
            break;
        case 3: x = 5;
    }
    return x;
}

prog.cc: In function 'int main(int, const char**)':
prog.cc:3:9: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
    3 |     int x;
      |         ^

В данном конкретном случае решается с помощью конструкции default:

int main (int argc, const char * argv[])
{
    int x;
    switch (argc)
    {
        case 1: x = 1;
            break;
        case 2: x = 4;
            break;
        case 3: x = 5;
            break;
        default:
            x = 17;
    }
    return x;
}

-Wmemset-elt-size

Предупреждает о подозрительных вызовах функции memset, когда первый аргумент — это массив, а третий аргумент — количество элементов в массиве, но не количество байт, занимаемой этим массивом в памяти.

#include <cstring>

int main ()
{
    constexpr auto size = 20ul;
    int a[size];
    std::memset(a, 0, size);
}

prog.cc: In function 'int main()':
prog.cc:7:27: warning: 'memset' used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
    7 |     std::memset(a, 0, size);
      |                           ^

-Wmemset-transposed-args

Предупреждает о том, что пользователь, вероятно, перепутал порядок аргументов в функции memset:

#include <cstring>

int main ()
{
    constexpr auto size = 20ul;
    int a[size];
    std::memset(a, size, 0);
}

prog.cc: In function 'int main()':
prog.cc:7:27: warning: 'memset' used with constant zero length parameter; this could be due to transposed parameters [-Wmemset-transposed-args]
    7 |     std::memset(a, size, 0);
      |                           ^

-Wmisleading-indentation

Предупреждает о том, что отступы в коде не отражают структуру этого кода. Особенно это актуально для конструкций if, else, while и for. Пример:

int main ()
{
    int x;
    if (true)
        x = 3;
        return x;
}

prog.cc: In function 'int main()':
prog.cc:4:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    4 |     if (true)
      |     ^~
prog.cc:6:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    6 |         return x;
      |         ^~~~~~

См. также -Wempty-body.

-Wmissing-attributes

Предупреждает о ситуации, когда специализация шаблона объявлена не с тем же списком атрибутов, что и оригинальный шаблон.

template <class T>
T* __attribute__ ((malloc, alloc_size (1)))
foo (long);

template <>
void* __attribute__ ((malloc))
foo<void> (long);

int main ()
{
}

prog.cc:7:1: warning: explicit specialization 'T* foo(long int) [with T = void]' may be missing attributes [-Wmissing-attributes]
    7 | foo<void> (long);
      | ^~~~~~~~~
prog.cc:3:1: note: missing primary template attribute 'alloc_size'
    3 | foo (long);
      | ^~~

-Wmultistatement-macros

Предупреждает о макросах, состоящих из нескольких инструкций, и используемых в выражениях if, else, while и for. В такой ситуации под действие выражений попадает только первая инструкция макроса, и это, вероятно, ошибка:

#define INCREMENT x++; y++

int main ()
{
    int x = 0;
    int y = 0;
    if (true)
        INCREMENT;
}

prog.cc: In function 'int main()':
prog.cc:1:19: warning: macro expands to multiple statements [-Wmultistatement-macros]
    1 | #define INCREMENT x++; y++
      |                   ^
prog.cc:8:9: note: in expansion of macro 'INCREMENT'
    8 |         INCREMENT;
      |         ^~~~~~~~~
prog.cc:7:5: note: some parts of macro expansion are not guarded by this 'if' clause
    7 |     if (true)
      |     ^~

См. также -Wmisleading-indentation.

-Wnonnull

Предупреждает о передаче нулевого указателя в функцию, аргументы которой помечены атрибутом nonnull.

void f (int * ptr) __attribute__((nonnull));

int main ()
{
    f(nullptr);
}

void f (int *) {}

prog.cc: In function 'int main()':
prog.cc:5:14: warning: null argument where non-null required (argument 1) [-Wnonnull]
    5 |     f(nullptr);
      |              ^

-Wnonnull-compare

Предупреждает о сравнении с нулём аргумента функции, помеченного атрибутом nonnull.

bool f (int * ptr) __attribute__((nonnull));

int main ()
{
    f(nullptr);
}

bool f (int * p)
{
    return p == nullptr;
}

prog.cc: In function 'bool f(int*)':
prog.cc:10:17: warning: nonnull argument 'p' compared to NULL [-Wnonnull-compare]
   10 |     return p == nullptr;
      |                 ^~~~~~~

-Wparentheses

Типичный случай — опечатались, и вместо равенства написали присвоение:

int main ()
{
    int x = 5;
    if (x = 4)
    {
        x = 3;
    }
}

Компилятор, естественно, сомневается:

prog.cc: In function 'int main()':
prog.cc:4:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    4 |     if (x = 4)
      |         ~~^~~

Либо исправляем код, либо убеждаем компилятор в том, что мы хотели именно присвоение:

int main ()
{
    int x = 5;
    if ((x = 4))
    {
        x = 3;
    }
}

-Wpessimizing-move

Иногда явная попытка переноса может ухудшить производительность. Пример:

#include <utility>

struct A {};

A f ()
{
    A a;
    return std::move(a);
}

int main ()
{
    f();
}

prog.cc: In function 'A f()':
prog.cc:8:21: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
    8 |     return std::move(a);
      |            ~~~~~~~~~^~~
prog.cc:8:21: note: remove 'std::move' call

-Wreorder

Предупреждает о том, что порядок инициализации членов класса не соответствует порядку их объявления. Поскольку компилятор может переупорядочить инициализацию этих членов, результат может быть неочевидным.

struct A
{
    int i;
    int j;

    A(): j(0), i(1)
    {
    }
};

int main () {}

prog.cc: In constructor 'A::A()':
prog.cc:4:9: warning: 'A::j' will be initialized after [-Wreorder]
    4 |     int j;
      |         ^
prog.cc:3:9: warning:   'int A::i' [-Wreorder]
    3 |     int i;
      |         ^
prog.cc:6:5: warning:   when initialized here [-Wreorder]
    6 |     A(): j(0), i(1)
      |     ^

-Wreturn-type

Предупреждает о том, что из функции не вернули заявленный результат:

int f ()
{
}

int main () {}

prog.cc: In function 'int f()':
prog.cc:3:1: warning: no return statement in function returning non-void [-Wreturn-type]
    3 | }
      | ^

-Wsequence-point

Сообщает о подозрительных операциях относительно точек следования. Любимый пример (никогда так не делайте):

int main ()
{
    int a = 6;
    ++a = a++;
}

prog.cc: In function 'int main()':
prog.cc:4:12: warning: operation on 'a' may be undefined [-Wsequence-point]
    4 |     ++a = a++;
      |           ~^~

-Wsign-compare

Одно из важнейших предупреждений. Сообщает о сравнении знаковых и беззнаковых чисел, которое может произвести некорректный результат из-за неявных преобразований. К примеру, отрицательное знаковое число неявно приводится к беззнаковому и внезапно становится положительным:

int main ()
{
    short a = -5;
    unsigned b = 4;
    if (a < b)
    {
        return 0;
    }

    return 1;
}

prog.cc: In function 'int main()':
prog.cc:5:11: warning: comparison of integer expressions of different signedness: 'short int' and 'unsigned int' [-Wsign-compare]
    5 |     if (a < b)
      |         ~~^~~

-Wsizeof-pointer-div

Предупреждает о подозрительном делении друг на друга двух результатов выражения sizeof, когда размер указателя делится на размер объекта. Обычно это бывает, когда пытаются вычислить размер массива, но вместо массива по ошибке берут указатель:

int main ()
{
    const char * a = "12345";
    auto size = sizeof (a) / sizeof (a[0]);
}

prog.cc: In function 'int main()':
prog.cc:4:28: warning: division 'sizeof (const char*) / sizeof (const char)' does not compute the number of array elements [-Wsizeof-pointer-div]
    4 |     auto size = sizeof (a) / sizeof (a[0]);
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~
prog.cc:3:18: note: first 'sizeof' operand was declared here
    3 |     const char * a = "12345";
      |                  ^

-Wsizeof-pointer-memaccess

Предупреждает о подозрительных параметрах, передаваемых в строковые функции и функции для работы с памятью (str..., mem... и т.п.), и использующих оператор sizeof. Например:

#include <cstring>

int main ()
{
    char a[10];
    const char * s = "qwerty";
    std::memcpy (a, s, sizeof(s));
}

prog.cc: In function 'int main()':
prog.cc:7:24: warning: argument to 'sizeof' in 'void* memcpy(void*, const void*, size_t)' call is the same expression as the source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
    7 |     std::memcpy (a, s, sizeof(s));
      |                        ^~~~~~~~~

-Wstrict-aliasing

Каламбур типизации (strict aliasing) — это отдельная большая тема для разговора. Предлагаю читателю найти литературу по этой теме самостоятельно.

В общем, это тоже крайне полезное предупреждение.

-Wswitch

Предупреждает о том, что не все элементы перечисления задействованы в конструкции switch:

enum struct enum_t
{
    a, b, c
};

int main ()
{
    enum_t e = enum_t::a;
    switch (e)
    {
        case enum_t::a:
        case enum_t::b:
            return 0;
    }
}

prog.cc: In function 'int main()':
prog.cc:9:12: warning: enumeration value 'c' not handled in switch [-Wswitch]
    9 |     switch (e)
      |            ^

-Wtautological-compare

Предупреждает о бессмысленном сравнении переменной с самой собой:

int main ()
{
    int i = 1;
    if (i > i);
}

prog.cc: In function 'int main()':
prog.cc:4:11: warning: self-comparison always evaluates to false [-Wtautological-compare]
    4 |     if (i > i);
      |         ~ ^ ~

Кроме того, сообщает о сравнениях при участии битовых операций, которые имеют всегда один и тот же результат (всегда истинно или всегда ложно):

int main ()
{
    int i = 1;
    if ((i & 16) == 10);
}

prog.cc: In function 'int main()':
prog.cc:4:18: warning: bitwise comparison always evaluates to false [-Wtautological-compare]
    4 |     if ((i & 16) == 10);
      |         ~~~~~~~~ ^~ ~~

-Wtrigraphs

Предупреждает о наличии триграфов, которые могут изменить смысл программы. Не сообщается о триграфах в теле комментария, за исключением случаев, когда триграф трактуется как перевод строки.

См. также -Wcomment.

-Wuninitialized

Предупреждает об использовании переменных и членов класса, которые не были проинициализированы:

int main ()
{
    int x;
    return x;
}

prog.cc: In function 'int main()':
prog.cc:4:12: warning: 'x' is used uninitialized in this function [-Wuninitialized]
    4 |     return x;
      |            ^

-Wunused-function

Предупреждает о том, что статическая функция объявлена, но не определена, либо о том, что статическая функция, не помеченная как inline, не используется.

-Wunused-variable

Предупреждает о том, что переменная не используется.

int main ()
{
    int x = 0;
}

prog.cc: In function 'int main()':
prog.cc:3:9: warning: unused variable 'x' [-Wunused-variable]
    3 |     int x = 0;
      |         ^

Для того, чтобы помочь компилятору понять, что так и задумывалось, можно использовать конструкцию static_cast<void>(...):

int main ()
{
    int x = 0;
    static_cast<void>(x);
}

-Wextra

«Агрегатор» дополнительных предупреждений. Включает много интересного, чего нет в -Wall (как и в случае с -Wall, рассмотрены будут не все возможности).

В этом разделе:

  1. -Wempty-body
  2. -Wimplicit-fallthrough
  3. -Wmissing-field-initializers
  4. -Wredundant-move
  5. -Wtype-limits
  6. -Wshift-negative-value
  7. -Wunused-parameter
  8. -Wunused-but-set-parameter

-Wempty-body

Предупреждает о пустом теле условных выражений или цикла do-while. Чаще всего это говорит об опечатке, меняющей логику программы:

int main ()
{
    if (true);
    {
        return 1;
    }
}

prog.cc: In function 'int main()':
prog.cc:3:14: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
    3 |     if (true);
      |              ^

См. также -Wmisleading-indentation.

Предупреждает о «проваливании» в операторе switch:

int main ()
{
    int x = 7;
    int a;
    switch (x)
    {
        case 1:
            a = 1;
            break;
        case 2:
            a = 2;
        case 3:
            a = 3;
            break;
        default:
            a = 0;
    }
    return a;
}

Компилятор предполагает, что программист забыл break, и case 2 не должен проваливаться:

prog.cc: In function 'int main()':
prog.cc:11:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
   11 |             a = 2;
      |             ~~^~~
prog.cc:13:9: note: here
   13 |         case 3:
      |         ^~~~

В C++17 для обозначения явного намерения появился специальный атрибут — fallthrough:

int main ()
{
    int x = 7;
    int a;
    switch (x)
    {
        case 1:
            a = 1;
            break;
        case 2:
            a = 2;
            [[fallthrough]];
        case 3:
            a = 3;
            break;
        default:
            a = 0;
    }
    return a;
}

Предупреждает о том, что отдельные члены структуры не были проинициализированы. Скорее всего это просто забыли сделать:

struct S
{
    int f;
    int g;
    int h;
};

int main ()
{
    S s{3, 4};
}

prog.cc: In function 'int main()':
prog.cc:10:13: warning: missing initializer for member 'S::h' [-Wmissing-field-initializers]
   10 |     S s{3, 4};
      |             ^

Предупреждает о ненужном вызове std::move в случаях, когда компилятор сам сделает всё, что нужно:

#include <utility>

struct S {};

S f (S s)
{
    return std::move(s);
}

int main ()
{
    auto s = f(S{});
}

prog.cc: In function 'S f(S)':
prog.cc:7:21: warning: redundant move in return statement [-Wredundant-move]
    7 |     return std::move(s);
      |            ~~~~~~~~~^~~
prog.cc:7:21: note: remove 'std::move' call

Предупреждает о сравнениях, которые всегда имеют один и тот же результат. Например, когда беззнаковое число проверяется на неотрицательность. Если программист делает такую проверку, то, видимо, предполагает, что число в теории может быть отрицательным, однако, это не так. Видимо, он где-то ошибся:

int main ()
{
    unsigned x = 17;
    if (x >= 0)
    {
        return 1;
    }
}

prog.cc: In function 'int main()':
prog.cc:4:11: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
    4 |     if (x >= 0)
      |         ~~^~~~

Предупреждает об операциях сдвига для отрицательных значений. Отрицательными могут быть только знаковые числа, а для них это некорректно:

int main ()
{
    const int x = -7;
    return x << 4;
}

prog.cc: In function 'int main()':
prog.cc:4:17: warning: left shift of negative value [-Wshift-negative-value]
    4 |     return x << 4;
      |                 ^

Предупреждает о неиспользуемом параметре функции. Возможно, про него просто забыли, и в этом случае функция может работать некорректно.

void f (int x) {}

int main ()
{
}

prog.cc: In function 'void f(int)':
prog.cc:1:13: warning: unused parameter 'x' [-Wunused-parameter]
    1 | void f (int x) {}
      |         ~~~~^

В C++17 для явного выражения намерения существует атрибут maybe_unused:

void f ([[maybe_unused]] int x) {}

int main ()
{
}

Предупреждает о том, что в параметр функции было записано значение, но после этого он ни разу не использовался. Возможно, про него снова забыли:

void f (int x)
{
    x = 7;
}

int main ()
{
}

prog.cc: In function 'void f(int)':
prog.cc:1:13: warning: parameter 'x' set but not used [-Wunused-but-set-parameter]
    1 | void f (int x)
      |         ~~~~^

-Wpedantic

-Wall и -Wextra — это не всё, на что способен компилятор.

В дополнение к ним существует флаг -Wpedantic (он же -pedantic), который проверяет соответствие кода стандарту ISO C++, сообщает об использовании запрещённых расширений, о наличии лишних точек с запятой, нехватке переноса строки в конце файла и прочих полезных штуках.

Нужно больше предупреждений

Но и это ещё не всё. Есть несколько флагов, которые почему-то не входят ни в один из «аргегаторов», но крайне важны и полезны.

В этом разделе:

  1. -Wctor-dtor-privacy
  2. -Wnon-virtual-dtor
  3. -Wold-style-cast
  4. -Woverloaded-virtual
  5. -Wsign-promo
  6. -Wduplicated-branches
  7. -Wduplicated-cond
  8. -Wfloat-equal
  9. -Wshadow=compatible-local
  10. -Wcast-qual
  11. -Wconversion
  12. -Wzero-as-null-pointer-constant
  13. -Wextra-semi
  14. -Wsign-conversion
  15. -Wlogical-op

-Wctor-dtor-privacy

Предупреждает о том, что класс выглядит неиспользуемым, потому что конструкторы и деструкторы закрыты, а друзей и открытых статических функций-членов у него нет.

class base
{
    base () {};
    ~base() {};
};

int main ()
{
}

prog.cc:1:7: warning: 'class base' only defines a private destructor and has no friends [-Wctor-dtor-privacy]
    1 | class base
      |       ^~~~

Аналогично, сообщает, что у класса есть закрытые функции-члены, а открытых нет ни одной.

-Wnon-virtual-dtor

Предупреждает о том, что у класса есть виртуальные функции-члены, но деструктор при этом не виртуальный. Очень сложно представить себе такой класс. Вероятнее всего, это ошибка.

struct base
{
    virtual void f (int) {}
    ~base() {};
};

int main ()
{
}

prog.cc:1:8: warning: 'struct base' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
    1 | struct base
      |        ^~~~

-Wold-style-cast

Предупреждает о приведении типов в стиле языка C. В плюсах есть прекрасные и ужасные static_cast, dynamic_cast, reinterpret_cast и const_cast, которые более локальны и более описательны. Сишный способ слишком сильный и — о, ужас, — небезопасный. Лучше его не использовать вообще.

-Woverloaded-virtual

Предупреждает о попытке в классе-наследнике перегрузить виртуальную функцию базового класса:

struct base
{
    virtual void f (int) {}
};

struct derived: base
{
    void f () {};
};

int main ()
{
}

prog.cc:3:18: warning: 'virtual void base::f(int)' was hidden [-Woverloaded-virtual]
    3 |     virtual void f (int) {}
      |                  ^
prog.cc:8:10: warning:   by 'void derived::f()' [-Woverloaded-virtual]
    8 |     void f () {};
      |          ^

-Wsign-promo

Крайне полезный флаг. Предупреждает о неочевидном выборе перегруженной функции:

void f (int) {}
void f (unsigned) {}

int main ()
{
    unsigned short x = 7;
    f(x);
}

prog.cc: In function 'int main()':
prog.cc:7:8: warning: passing 'short unsigned int' chooses 'int' over 'unsigned int' [-Wsign-promo]
    7 |     f(x);
      |        ^
prog.cc:7:8: warning:   in call to 'void f(int)' [-Wsign-promo]

Вероятнее всего, хотели-таки позвать вторую перегрузку, а не первую. А если всё-таки первую, то будьте любезны сказать об этом явно.

-Wduplicated-branches

Предупреждает о том, что ветви if и else одинаковы:

int main ()
{
    if (true)
        return 0;
    else
        return 0;
}

prog.cc: In function 'int main()':
prog.cc:3:5: warning: this condition has identical branches [-Wduplicated-branches]
    3 |     if (true)
      |     ^~

Условный оператор ?: также под прицелом:

int main ()
{
    auto x = true ? 4 : 4;
}

prog.cc: In function 'int main()':
prog.cc:3:19: warning: this condition has identical branches [-Wduplicated-branches]
    3 |     auto x = true ? 4 : 4;
      |              ~~~~~^~~~~~~

Для меня абсолютная загадка, почему этот флаг не включён не то, что в -Wall, а вообще по умолчанию.

См. также -Wduplicated-cond.

-Wduplicated-cond

Предупреждает об одинаковых условиях в цепочках if-else-if:

int main ()
{
    auto x = 6;
    if (x > 7) {return 0;}
    else if (x > 7) {return 1;}
}

prog.cc: In function 'int main()':
prog.cc:5:10: warning: duplicated 'if' condition [-Wduplicated-cond]
    5 |     else if (x > 7) {return 1;}
      |          ^~
prog.cc:4:5: note: previously used here
    4 |     if (x > 7) {return 0;}
      |     ^~

См. также -Wduplicated-branches.

-Wfloat-equal

Предупреждает о проверке на равенство между двумя числами с плавающей точкой. Скорее всего, это ошибка, и сравнение нужно проводить с заданной точностью.

Если же требуется именно сравнить на равенство (такое редко, но бывает), то можно использовать std::equal_to, который под предупреждение не попадает.

-Wshadow=compatible-local

Полезная опция, которая не даёт перекрыть локальную переменную другой локальной переменной при условии, что они имеют совместимые типы.

-Wcast-qual

Предупреждает о преобразовании указателя, при котором сбрасываются квалификаторы. Например, чтобы случайно не потерять const.

-Wconversion

Очень, очень, очень важный флаг. Он предупреждает об огромном количестве неявных сужающих (то есть потенциально приводящих к потере информации) преобразований, которые могут быть следствием ошибки программиста. Например:

int main ()
{
    double x = 4.5;
    int y = x;
}

prog.cc: In function 'int main()':
prog.cc:12:13: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
   12 |     int y = x;
      |             ^

Если вы раньше никогда не включали этот флаг, то будет интересно.

-Wzero-as-null-pointer-constant

Предупреждает об использовании целочисленного нуля вместо nullptr.

Флаг для педантов. Сообщает о лишней точке с запятой после определения функции-члена.

-Wsign-conversion

Как и -Wconversion помогает предотвратить большое количество неявных преобразований, которые запросто могут быть ошибками:

int main ()
{
    signed si = -8;
    unsigned ui;
    ui = si;
}

prog.cc: In function 'int main()':
prog.cc:5:10: warning: conversion to 'unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    5 |     ui = si;
      |          ^~

-Wlogical-op

Предупреждает о подозрительных логических выражениях. Например, когда вместо побитового «И» поставили логическое «И», или логическое выражение имеет одинаковые операнды:

int main ()
{
    int a = 8;
    if (a < 0 && a < 0)
    {
        return 1;
    }
}

prog.cc: In function 'int main()':
prog.cc:4:15: warning: logical 'and' of equal expressions [-Wlogical-op]
     if (a < 0 && a < 0)
         ~~~~~~^~~~~~~~

-Werror

С этого, вообще говоря, стоило бы начать. Данный флаг делает все предупреждения ошибками. Код не скомпилируется при наличии хотя бы одного предупреждения.

Без этого флага всё остальное имеет мало смысла. Но если понять и принять мысль о том, что предупреждение — это что-то подозрительное, и их быть не должно, то именно этот флаг и позволит поддерживать код в чистоте.

В дополнение к -Werror существует флаг -pedantic-errors, который не эквивалентен комбинации -Wpedantic -Werror.

Да, всё непросто.

Заключение

Резюмируя, для компилятора GCC (Clang кое-что из этого не умеет, к сожалению) я рекомендую включать следующий минимальный набор флагов, по необходимости дополняя его более сложными диагностиками.

-Werror
-pedantic-errors

-Wall
-Wextra
-Wpedantic

-Wcast-align
-Wcast-qual
-Wconversion
-Wctor-dtor-privacy
-Wduplicated-branches
-Wduplicated-cond
-Wextra-semi
-Wfloat-equal
-Wlogical-op
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wsign-conversion
-Wsign-promo

Да, такой список флагов может породить большое количество ошибок, которые поначалу могут показаться излишними. Но явное лучше неявного. Если знаешь, что делаешь — делай. Но делай это так, чтобы всем было понятно, что именно так ты и хотел. Поработав таким образом хотя бы неделю, вы поймёте, насколько это прекрасно, и уже не сможете вернуться обратно.

Любите ваш компилятор и помогайте ему помогать вам писать программы.

Ссылки

  1. Документация к компилятору GCC
  2. Документация к компилятору Clang

I was just talking with a co-worker about this this morning as well — it’s really unfortunate, but I think handling the default is required for safety, for two reasons:

First, as your co-worker mentions, it future-proofs the code against new values being added to the enum. This may or may not seem like a possibility, but it’s always there.

More importantly, depending on the language/compiler, it may be possible to have values that aren’t members of the enum in your switched variable. For example, in C#:

MyEnum myEnum = (MyEnum) 3; // This could come from anywhere, maybe parsed from text?
// ... code goes on for a while

switch ( myEnum )
{
    case MyEnum.A:
        // ... handle A case
        break;
    case MyEnum.B:
        // ... handle B case
        break;
}

// ... code that expects either A or B to have happened

By adding the simple case default: and throwing an exception, you’ve protected yourself against this weird case where «nothing» happens but «something» should have happened.

Unfortunately, basically any time I write a switch statement anymore, it’s because I’m checking the cases of an enum. I really wish the «throw by default» behavior could be enforced by the language itself (at least by adding a keyword).

03-20-2011


#1

Richardcavell is offline


Registered User


Enumeration values not handled

Hi, all. I’m compiling with gcc -Wall -Wextra. My functions return an enumeration to the caller, and then the caller deals with it like this:

Code:

switch (result)
{
case success:
   /*blah*/
case failure:
  /*blah*/
case another:
  /*blah*/
}

Now, my switch statements do not handle all possible values within the enumeration, because I know that it is (or should be) impossible for certain values to be returned in certain circumstances. GCC gives me:

warning: enumeration value ‘another’ not handled in switch
warning: control reaches end of non-void function

Now whatever code GCC is generating for the other values of the switch, I know it can never be executed. What’s the ‘proper’ way of dealing with this?

Richard (TIA)


I am trying to compile following code without warnings:

    while (window.pollEvent(event))
    {
        switch (event.type) {
            case sf::Event:::
                window.close(); break;
            case sf::Event::KeyPressed:
                if(event.key.code == sf::Keyboard::Escape )
                    window.close();
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Space ) )
                    particleSystem.fuel( 200/* * window.getFrameTime() */);
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::A ) )
                    particleSystem.setPosition( --xpos, ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
                    particleSystem.setPosition( ++xpos, ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::W ) )
                    particleSystem.setPosition( xpos, --ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::S ) )
                    particleSystem.setPosition( xpos, ++ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
                    particleSystem.setGravity( --xgrv * 0.1f, ygrv * 0.1f);
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
                    particleSystem.setGravity( ++xgrv * 0.1f, ygrv * 0.1f );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
                    particleSystem.setGravity( xgrv * 0.1f, --ygrv * 0.1f );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
                    particleSystem.setGravity( xgrv * 0.1f, ++ygrv * 0.1f );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::G ) )
                    particleSystem.setGravity( 0.0f, 0.0f );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::P ) )
                    particleSystem.setPosition( 320.0f, 240.0f );
                break;
    }

however, I am getting a lot of warnings:

/home/bluszcz/private/repo/deerportal/game.cpp:444: warning: enumeration value 'LostFocus' not handled in switch [-Wswitch]

Which in my it is not an issue, since I am don’t need handling all types of the events.

Adding

default:
    break;

to my code removes the warnings, however is it a best way to solve this issue?

Basic Enumeration Declaration

Standard enumerations allow users to declare a useful name for a set of integers. The names are collectively referred to as enumerators. An enumeration and its associated enumerators are defined as follows:

enum myEnum
{
    enumName1,
    enumName2,
};

An enumeration is a type, one which is distinct from all other types. In this case, the name of this type is myEnum. Objects of this type are expected to assume the value of an enumerator within the enumeration.

The enumerators declared within the enumeration are constant values of the type of the enumeration. Though the enumerators are declared within the type, the scope operator :: is not needed to access the name. So the name of the first enumerator is enumName1.

C++11

The scope operator can be optionally used to access an enumerator within an enumeration. So enumName1 can also be spelled myEnum::enumName1.

Enumerators are assigned integer values starting from 0 and increasing by 1 for each enumerator in an enumeration. So in the above case, enumName1 has the value 0, while enumName2 has the value 1.

Enumerators can also be assigned a specific value by the user; this value must be an integral constant expression. Enumerators who’s values are not explicitly provided will have their value set to the value of the previous enumerator + 1.

enum myEnum
{
    enumName1 = 1, // value will be 1
    enumName2 = 2, // value will be 2
    enumName3,     // value will be 3, previous value + 1
    enumName4 = 7, // value will be 7
    enumName5,     // value will be 8
    enumName6 = 5, // value will be 5, legal to go backwards
    enumName7 = 3, // value will be 3, legal to reuse numbers
    enumName8 = enumName4 + 2, // value will be 9, legal to take prior enums and adjust them
};

Enumeration in switch statements

A common use for enumerators is for switch statements and so they commonly appear in state machines. In fact a useful feature of switch statements with enumerations is that if no default statement is included for the switch, and not all values of the enum have been utilized, the compiler will issue a warning.

enum State {
    start,
    middle,
    end
};

...

switch(myState) {
    case start:
       ...
    case middle:
       ...
} // warning: enumeration value 'end' not handled in switch [-Wswitch]

Iteration over an enum

There is no built-in to iterate over enumeration.

But there are several ways

  • for enum with only consecutive values:

    enum E {
        Begin,
        E1 = Begin,
        E2,
        // ..
        En,
        End
    };
    
    for (E e = E::Begin; e != E::End; ++e) {
        // Do job with e
    }
    

C++11

with enum class, operator ++ has to be implemented:

E& operator ++ (E& e)
{
    if (e == E::End) {
        throw std::out_of_range("for E& operator ++ (E&)");
    }
    e = E(static_cast<std::underlying_type<E>::type>(e) + 1);
    return e;
}
  • using a container as std::vector

    enum E {
        E1 = 4,
        E2 = 8,
        // ..
        En
    };
    
    std::vector<E> build_all_E()
    {
        const E all[] = {E1, E2, /*..*/ En};
        
        return std::vector<E>(all, all + sizeof(all) / sizeof(E));
    }
    
    std::vector<E> all_E = build_all_E();
    

    and then

    for (std::vector<E>::const_iterator it = all_E.begin(); it != all_E.end(); ++it) {
        E e = *it;
        // Do job with e;
    }
    

C++11

  • or std::initializer_list and a simpler syntax:

    enum E {
        E1 = 4,
        E2 = 8,
        // ..
        En
    };
    
    constexpr std::initializer_list<E> all_E = {E1, E2, /*..*/ En};
    

    and then

    for (auto e : all_E) {
        // Do job with e
    }
    

Scoped enums

C++11 introduces what are known as scoped enums. These are enumerations whose members must be qualified with enumname::membername. Scoped enums are declared using the enum class syntax. For example, to store the colors in a rainbow:

enum class rainbow {
    RED,
    ORANGE,
    YELLOW,
    GREEN,
    BLUE,
    INDIGO,
    VIOLET
};

To access a specific color:

rainbow r = rainbow::INDIGO;

enum classes cannot be implicitly converted to ints without a cast. So int x = rainbow::RED is invalid.

Scoped enums also allow you to specify the underlying type, which is the type used to represent a member. By default it is int. In a Tic-Tac-Toe game, you may store the piece as

enum class piece : char {
    EMPTY = '',
    X = 'X',
    O = 'O',
};

As you may notice, enums can have a trailing comma after the last member.

Enum forward declaration in C++11

Scoped enumerations:

...
enum class Status; // Forward declaration 
Status doWork(); // Use the forward declaration
...
enum class Status { Invalid, Success, Fail };
Status doWork() // Full declaration required for implementation
{
    return Status::Success;
}    

Unscoped enumerations:

...
enum Status: int; // Forward declaration, explicit type required
Status doWork(); // Use the forward declaration
...
enum Status: int{ Invalid=0, Success, Fail }; // Must match forward declare type
static_assert( Success == 1 );

An in-depth multi-file example can be found here: Blind fruit merchant example

  • Forum
  • General C++ Programming
  • sfml- warning

sfml- warning

I star to learn sfml(C::B, win7).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include<iostream>
using namespace std;

int main()
{
    // Create the main window
sf::Window window;
window.create(sf::VideoMode(800,600),"opengl",sf::Style::Default);
    	// Start the game loop
	window.setVerticalSyncEnabled(true); // call it once, after creating the window

    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            switch(event.type){
            case sf::Event::Closed:  window.close();break;
            case sf::Event::KeyReleased:
                    switch(event.key.code){
                    case sf::Keyboard::Escape: cout<<"escape press"<<endl;break;
                    case sf::Keyboard::RShift : cout<<"rshift press"<<endl;break;
                    case sf::Keyboard::LShift: cout<<"lshift press"<<endl;break;

                    }
            }


            }

        
        window.display();
    }

    return EXIT_SUCCESS;
}

warning on line 24:- warning: enumeration value ‘A’ not handled in switch [-Wswitch]|
|warning: enumeration value ‘B’ not handled in switch [-Wswitch]|
…………………………………………
warning: enumeration value ‘D’ not handled in switch [-Wswitch]|
_______________________________________________________________________
similarly line 21:
warning: enumeration value ‘Num0’ not handled in switch [-Wswitch]|
……………………….
warning: enumeration value ‘Num9’ not handled in switch [-Wswitch]|
enumeration value ‘LControl’ not handled in switch [-Wswitch]|

similarly
‘LAlt’,’LSystem’ ‘RControl’

warning: enumeration value ‘Space’ not handled in switch [-Wswitch]|
warning: enumeration value ‘Return’ not handled in switch [-Wswitch]|

how to handle this.

Last edited on

What’s the problem?

May I suggest using if-else rather than a switch as the warnings seems to suggest that the switch will not work with the enums. Also, if you really want to condense your code that much it is entirely possible to do it in just as short a number of lines with repeated ifs and elses.

May I suggest using if-else rather than a switch

Nah, just add a default case in your switch/case statement

1
2
3
4
5
6
7
8
9
10
11
12
            switch(event.type){
            case sf::Event::Closed:  window.close();break;
            case sf::Event::KeyReleased:
                    switch(event.key.code){
                    case sf::Keyboard::Escape: cout<<"escape press"<<endl;break;
                    case sf::Keyboard::RShift : cout<<"rshift press"<<endl;break;
                    case sf::Keyboard::LShift: cout<<"lshift press"<<endl;break;

                    default: break;
                    }
            default: break;
            }

Last edited on

Firstly, these are «only» warnings. This is legal C++, and will compile and run. A warning means that the compiler has identified something unusual, that might lead to problems, or lead to the program doing something that you don’t expect, or else something that might indicate you’ve made a mistake.

While you can ignore warnings, it’s generally a good idea to understand them, examine the code that’s causing them, and fix them where possible.

I’m not familiar with C:B, but a quick Google search (which you could have done yourself, trivially) tells me that the compiler is warning you that there are some possible values of the enum that aren’t handled by cases in your switch statement. So, for example, event.type can take values other than Closed or KeyReleased, and if it does have one of those other values, then it won’t trigger any of the cases in your switch problem.

This is perfectly legal, but it’s the sort of thing that can sometimes mean that the developer has accidentally forgotten to write a case handling a possible value, so the compiler writers thought it would be helpful to warn you when it happens.

Some developers would say that if this is what you genuinely want to happen, then it would be good style to add a default block that does nothing, e.g.

20
21
22
23
24
25
26
27
28
29
30
31
            // Close window : exit
            switch(event.type){
            case sf::Event::Closed:  window.close();break;
            case sf::Event::KeyReleased:
                    switch(event.key.code){
                            // ...
                    }
                    break;
            }
           default:  
                    // Do nothing for other event types
                    break;

Your code then documents that the missing case statements are not accidental, but that you intended it to work this way.

Last edited on

problem is switch statement. but why?
@Gamer2015 (394)
why warning? how to make my code fresh

Last edited on

Um… did you miss my post? I explained what the problem was, and one way to fix it.

Last edited on

thx every one.
add default work fine.

You’re welcome! Glad we could help.

Topic archived. No new replies allowed.

Понравилась статья? Поделить с друзьями:
  • Error establishing a database connection что это значит
  • Error establishing a database connection wordpress что делать
  • Error establishing a database connection wordpress multisite
  • Error establishing a database connection wordpress centos
  • Error establishing a database connection ubuntu wordpress