警告是:
/home/dronz/OF/apps/myApps/HexMap/src/HexMap.cpp:48:5: warning:
this ‘if’ clause does not guard... [-Wmisleading-indentation]
if (toHexSize < 1)
^~
/home/dronz/OF/apps/myApps/HexMap/src/HexMap.cpp:51:2: note: ...
this statement, but the latter is misleadingly indented as
if it were guarded by the ‘if’
MapTileSizeAtZoom = toHexSize;
^~~~~~~~~~~~~~~~~
密码是:
if (toHexSize < 1)
toHexSize = 1;
MapTileSizeAtZoom = toHexSize;
如果MapTileSizeAtZoom ...
行缩得更多,我可以看到它是误导的,但它与' if‘处于相同的缩进水平,所以这在我看来是正确的。
我想可能有额外的空格和/或制表符浮动,但我削减了任何不必要的空格字符后,文字,这没有什么区别。
我想它可能被空白行弄糊涂了,但是把它拿出来并没有停止警告。
此外,在同一.cpp文件中的前面是以下代码,它不对此代码发出警告:
if (toHexSize < 1)
toHexSize = 1;
HexInfo centerOnHex;
if (SelectedHex.type != -1)
为什么要警告一个,为什么不警告另一个,这是不是GCC的错误,我该怎么做才能避免呢?
代码
#include "HexMap.h"
#include <algorithm>
#include <cmath>
//--------------------------------------------------------------
HexMap::HexMap()
{}
//--------------------------------------------------------------
int HexMap::SetZoom(int toHexSize)
{
if (toHexSize < 1)
toHexSize = 1;
HexInfo centerOnHex;
if (SelectedHex.type != -1)
{
// Center map on the selected hex.
centerOnHex = SelectedHex;
}
else
{
// Center map on current center of viewpoint.
centerOnHex = GetHex(
MapFrame.x + MapFrame.getWidth() / 2,
MapFrame.y + MapFrame.getHeight() / 2 );
if ((centerOnHex.x > WORLDMAPWIDTH) || (centerOnHex.x < 0))
centerOnHex.x = WORLDMAPWIDTH / 2;
if ((centerOnHex.y > WORLDMAPHEIGHT) || (centerOnHex.y < 0))
centerOnHex.y = WORLDMAPHEIGHT / 2;
}
setHexDisplaySize(toHexSize);
// Center map:
HexOriginX = MapFrame.x + MapTileWidth * 0.25f;
HexOriginY = MapFrame.y + MapTileHeight * 0.5f;
ViewPosOnWorld.set(
centerOnHex.x - (MapFrame.getWidth() / 2) / MapTileWidth,
centerOnHex.y - (MapFrame.getHeight() / 2) / MapTileHeight);
return 0;
}
//--------------------------------------------------------------
void HexMap::setHexDisplaySize(int toHexSize)
{
if (toHexSize < 1)
toHexSize = 1;
MapTileSizeAtZoom = toHexSize;
MapTileWidth = MapTileSizeAtZoom * 1.5f; // hex x-spacing is 1.5 * r
MapTileHeight = MapTileSizeAtZoom * 1.73205f; // hex height = sqrt(3*r)
// Size images & hexmask:
MaskWidth = MapTileHeight * 1.154700538; // 1/(sqrt(3)/2)
}
发布于 2018-05-13 17:45:27
有用于缩进条件行49的空格,但a选项卡用于缩进第51行。
标签被GCC视为8个空格。编译器错误地认为它与if语句是对齐的,尽管在编辑器中它看起来并不是这样。这是与空白缩进保持一致的另一个原因(例如,避免在源代码中使用任何制表符)。
https://stackoverflow.com/questions/50318900
复制相似问题